#I get this in the logs when the script

1 messages ยท Page 1 of 1 (latest)

storm thunder
#

Sounds like you've got a problem with

  count: "{{ states('input_number.whale_count') }}"

You did create that entity, and give it a value?

drifting apex
#

What I did was creating a script in the UI with count number and delay then switching to YAML and replacing count and delay with that

storm thunder
#

states('input_number.whale_count') takes the state of input_number.whale_count - if you didn't create input_number.whale_count then there's nothing there... hence unknown

#

Similarly you need to have created input_number.second_delay and given it a valuue

drifting apex
#

A stupid question: How do I create an entity within the yaml for that

wintry pewterBOT
storm thunder
#

By following the docs for that integration

topaz roost
#

you can also create them in the GUI if you want

wintry pewterBOT
drifting apex
#

See the thing is when @storm thunder wrote count: "{{ states('input_number.whale_count') }}" the first time I pasted it into the script and ran it and it worked. I thought that was it.

#

But nowhere in helpers do I have the input number

#

And now it throws that error.

storm thunder
#

The script also didn't work... you got that error ๐Ÿ˜‰

drifting apex
#

Sorry I know how stupid I sound right now being newbie

storm thunder
#

Valid YAML != working

#

Eh, you're fine... you've been on the server long enough I assumed you'd an understanding of templates so that was my fault

drifting apex
#

That's right I joined some time back but haven't been able to keep following. I got homeassistant installed and properly setup only a few days ago. Moved over from Homekit/Homebridge to this as this has a lot to offer but there is much more to it than I thought.

#

Thanks for bearing here with me

#

do I need to add entities input_number and a delay in helpers?

storm thunder
#

You need to create both input_number entities

#

input_number.whale_count and input_number.second_delay

#

Or... created another two entities and used them in your automation/script

drifting apex
#

It doesn't need to be called whale_count does it?

storm thunder
#

No

drifting apex
#

ok

#

helpers defined and number input boxes

#

input_number.count and input_number.delay

#

Can I not send a screenshot here?

wintry pewterBOT
#

Please use imgur or other image sharing web sites, and share the link here.

Image posting is blocked in most channels to discourage people from sharing text as images. Sharing text as images assumes that everybody sees the world as you do, which isn't the case. Some people are colour blind, or have visual impairment that means they can't make sense of an image of text.

drifting apex
#

wow ok, a lot has changed since my last visit. OK

storm thunder
#

Test the template in devtools -> Templates

wintry pewterBOT
drifting apex
storm thunder
#

That's expected - remove that line

#

(or turn {{ there into { { to stop it parsing that)

#

I will repeat:

Sharing text as images assumes that everybody sees the world as you do, which isn't the case. Some people are colour blind, or have visual impairment that means they can't make sense of an image of text.

drifting apex
#

which line are you talking about

drifting apex
storm thunder
#

Right, but ... images of text are horrible

drifting apex
#

Correct

#

sorry

#

I know

#

repeat: count: "{{ states('input_number.count') }}" sequence: - delay: "{{ states('input_number.delay') | int }}" - service: notify.mobile_app_zenbook data: message: Seconds remain {{ count - repeat.index * delay }}

#

which line you said to remove

storm thunder
#

The last line

drifting apex
#

Sorry my HA is acting weird let me reboot

#

ok so I removed the last line and now I got the result

#

repeat: count: "10.0" sequence: - delay: "2" - service: notify.mobile_app_zenbook data:

storm thunder
#

Looks like the templates are good

#

You may need

  count: "{{ states('input_number.count')|int }}"
drifting apex
wintry pewterBOT
#

@drifting apex When using Discord's Reply feature it defaults to pinging the person you reply to, which can get frustrating for the target. Use Shift + click on the Reply option, or click @ ON to @ OFF to stop this - on the right side of the compose bar.

You have to change this every time (thank the Discord devs for that).

storm thunder
#

You also need to add the last line back...

#

I will say that in a thread like this Reply is pretty pointless, doubly so when you're using it to respond to the previous post

drifting apex
#

OK. got it

#

Added the last line back: repeat: count: count "{{ states('input_number.count')|int }}" sequence: - delay: "{{ states('input_number.delay')|int }}" - service: notify.mobile_app_zenbook data: message: Seconds remain {{ count - repeat.index * delay }}

#

When run getting this: 2022-12-13 14:57:48.617 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error rendering websocket_api script repeat count template: invalid literal for int() with base 10: 'count "10"'

storm thunder
#

No, look at the YAML you posted here, and compare it to what you had before

drifting apex
#

oh wait

storm thunder
#
  count: "{{ states('input_number.count') | int }}"
``` vs

count: count "{{ states('input_number.count')|int }}"

drifting apex
#

not only that

#

now I have this repeat: count: "{{ states('input_number.count')|int }}" sequence: - delay: "{{ states('input_number.delay')|int }}" - service: notify.mobile_app_zenbook data: message: Seconds remain {{ count - repeat.index * delay }}

wintry pewterBOT
storm thunder
#

That command there will help you

drifting apex
#

I get error that delay is undefined

storm thunder
#

It'll spot most YAML errors, including the ones you've made there

#

Right... where did you define the variable delay?

#

Hint ||nowhere||

drifting apex
#

in the helpers

#

it's set to 2

storm thunder
#

No, you didn't define delay there

#

You created the entity input_number.delay

#

At no point have you defined a variable called delay

drifting apex
#

in entities I opened the input_number.delay and set it to 2

#

same I did for the input_number.count and set it to 10

#

If I didn't define it how come templates showed the values?

storm thunder
#

Because delay != input_number.delay

#

count is defined automatically by the repeat loop, to the value of count: "{{ states('input_number.count')|int }}"

#

That you picked input_number.count is irrelevant - which is why I used input_number.whale_count

drifting apex
#

wait

#

what about this

storm thunder
drifting apex
#

repeat: count: "{{ states('input_number.count')|int }}" sequence: - delay: "00:00:0{{ states('input_number.delay')|int }}" - service: notify.mobile_app_zenbook data: message: Seconds remain {{ count - repeat.index * delay }}

#

this still throws delay undefined

storm thunder
#

Well, yes

#

Again...*** at no point do you define delay ***

#

Of course it's undefined, you've never defined it

#

input_number.delay is completely unrelated to delay

#

input_number.count is completely unrelated to count

drifting apex
#

I'm really confused now

#

sorry

storm thunder
#

Ok, take a step back

drifting apex
#

Ok..

storm thunder
#

input_number.count is an entity you created for this

drifting apex
#

yeah I created that entity

storm thunder
#

You could have called that input_number.banana

#
repeat:
  count: "{{ states('input_number.banana')|int }}"
#

There is no banana

drifting apex
#

Ok I get that it's a variable so whatever name doesn't matter

storm thunder
#

Well, no

#

It's an entity

#

It is not a variable

drifting apex
#

Ok

#

entity isn't a variable

storm thunder
#

Correct

#

Your repeat happens to create some variables automatically

#

At no point does a variable called delay get created - by you or HA

#
        message: "Seconds remain {{ states('input_number.count')|int - repeat.index * states('input_number.delay')|int }}"
drifting apex
#

Ah ok

#

Now I get it

#

Thanks. It worked now. However I still see that code {{ states('input_number.count')|int }} in the count number box instead of a number should it be that way?

storm thunder
#

Yes, the whole point is that it's a #templates-archived and the results of that template is used when the template is encountered

#

If it was a number you'd have hard-coded the value

drifting apex
#

So if I wanted to create another script like this to control another device with different count number and delay I'd have to create another entities with other values?

storm thunder
#

If you want to make them variable, yes

drifting apex
#

Thanks so much for being patient and explaining this to me.

#

What I thought was I'd be able to use the count box in the UI to define the count and wait UI for the delay

#

But turns out it's much more complex than that

storm thunder
#

Well, if you want to set them to fixed values you can

#

It's only if you want to make them things that you can change "on the fly" that it becomes complicated

drifting apex
#

I want to set them to fixed values for a script but want to be able to read those values later on in the script so that if I did decide to change the value I change it in the box and that's it. That was the goal

storm thunder
#

Well, you can do that with variables

#

Those are then fixed until you edit the script

drifting apex
#

Ok. question then. I haven't defined any entity. I simply created a script. In actions I added the repeat function. The repeat count box say I put 5 or 10 or 20. Is that value available as a variable in the script? So I could read it as say for example : input_number.count_box_value ???

storm thunder
#

I think it's available as count

drifting apex
#

nope didn't work for me

storm thunder
#

Then no

#

Because input_number.count_box_value isn't a variable anyway

#

That's an entity - the give away clue is the .

#

Variables have no .

drifting apex
#

ok.

#

I mean I just started doing all this, I can only imagine what your templates look like ๐Ÿ˜ฑ

storm thunder
#

Mine aren't special, mostly, except for a few crazy ones. The real experts lurk in #templates-archived and do things that make me ablobconfused

drifting apex
#

Can you please tell me why first time when I asked you said count: "{{ states('input_number.whale_count') }}" why does that whale matter? Why I'm asking is because when I put it in the YAML and returned to UI I was seeing the number in the count box. THe delay was fixed set to 2 and I ran the script and it worked.

storm thunder
#

Well, whale didn't matter

#

What mattered was that you had input_number.whale_count in your system, with a value

drifting apex
#

but how if I never defined it. I want understand why first time I saw number in the box and now I'm seeing the code

storm thunder
#

I have no idea what you did...

drifting apex
#

right now I also have input_number.count in the system with value 10. THe box doesn't show 10 it shows {{ states('input_number.count')|int }}

storm thunder
#

right, because you'd basically said you wanted to use templates

drifting apex
#

Sorry maybe I'm not being very clear.

storm thunder
#
script:
  thingy:
    alias: "thingy"
    variables:
      my_count: 10
      my_delay: 2
    sequence:
      repeat:
        count: "{{ my_count }}"
        sequence:
          - delay: "{{ my_delay }}"
          - service: notify.mobile_app_zenbook
            data:
              message: "Seconds remain {{ ( my_count * my_delay ) - ( repeat.index * my_delay ) }}"
#

(probably)

drifting apex
#

Can't save it: extra keys not allowed @ data['script']

#

it runs tho

#

works