Help with (what should be...) a basic template

Hi guys,

I’m tearing what’s left of my hair out over this.

I have three ‘alarm clocks’ that I can set to turn on the lights and play an alarm tone. One in my bedroom, one in the kids’ room, and one in the living room. They all work perfectly. Each has two input sliders, one for the hour and one for the minute so you can set the time for the alarm to go off.

What I want to achieve is a ‘master switch’ so that I can set all 3 at the same time. I have set up a group with two input sliders on it, one for hour and one for minute. The idea is to set those and press a button to run a script, and the script will set the 3 alarm clocks to the value I have set on the master switch.

Here is the code for the script:

all_sync:
  alias: Sync All Alarms
  sequence:
    - service: input_slider.select_value
      data: 
        entity_id:
          - input_slider.living_alarm_clock_hour
          - input_slider.boys_alarm_clock_hour
          - input_slider.masterbed_alarm_clock_hour
          #########What should the value be????########
        value: "{{states.input_slider.all_alarm_clock_hour.state}} | float"
    - service: input_slider.select_value
      data: 
        entity_id:
          - input_slider.living_alarm_clock_minute
          - input_slider.boys_alarm_clock_minute
          - input_slider.masterbed_alarm_clock_minute
          ########What should the value be????########
        value: "{{states.input_slider.all_alarm_clock_minute.state}} | float"

The problem is no matter what I try I get an error when I run the script. The errors vary a little with every combination I try, but they’re generally something like:

 Invalid service data for input_slider.select_value: expected float for dictionary value @ data['value']. Got '{{states.input_slider.all_alarm_clock_minute.state}} | float'

I’ve tried losing the quotes, double quotes, putting |float inside the braces, using ‘value_template’ instead of ‘value’, removing |float completely and I just can’t get it to work! For info , putting {{states.input_slider.all_alarm_clock_minute.state}} in to the developer template thingy brings back the value I want to send to the receiving input_sliders.

Somebody help!

Thanks in advance.

{{states.input_slider.all_alarm_clock_minute.state}} | float’

should be

{{states.input_slider.all_alarm_clock_minute.state | float}}

:slight_smile:

I’m sure i already tried that, but for completeness I’ve done it again:

{{states.input_slider.all_alarm_clock_minute.state | float}}

Without quotes around it = config error, HA won’t start
Single quotes around = runtime error: Invalid service data for input_slider.select_value: expected float for dictionary value @ data['value']. Got '{{states.input_slider.all_alarm_clock_minute.state | float}}'
Double quotes around it = same error as above

Thanks for trying.

Not sure you can do what you are trying to do but …

shouldn’t the value be…
value_template: ‘{{ now().time().strftime("%R") > “00:45” }}’
for e.g.

I have no idea, that’s why I’m stuck

Basically, if I pull the input slider alarm_clock_hour to 7 and alarm_clock_minute to 0 (for 7am) and then put {{{states.input_slider.all_alarm_clock_hour.state}} and {states.input_slider.all_alarm_clock_minute.state}} in to the developer thingy it shows 7 and 0. I then want to set the three alarm clock input sliders for hours to 7 and the sliders for minutes to 0 with the script, so I would’ve expected the above code to work. The first time I ran it I did not inlude the | float and it gave me the error message “expected float but got…” that I’m getting now, so I presumed it was returning an int or a string, I added |float to counteract that but the message is the same.

Setting the initial value of an input slider is as easy as typing the number you want it on, so surely sending it a number in input_slider.select_value is the same? Thusly, I should be able to set an input_slider based on the value of another?

Any thoughts?

Yes that should work something like that but as above shouldn’t the template be formatted as a template i.e. with value_template not value?

value_template: "{{states.input_slider.all_alarm_clock_minute.state | float}}"

With double quotes = runtime error: Invalid service data for input_slider.select_value: extra keys not allowed @ data[‘value_template’]. Got ‘{{states.input_slider.all_alarm_clock_minute.state | float}}’

With single quotes = same runtime error

With no quotes = config error, HA doesn’t start.

Thanks for your help so far.

What if you use
data_template:
instead of
data:
?

That’s what’s usually used to let HA know to parse a template.

It looks to me like you can’t set the value of multiple sliders with one call to the service.
This did not work for me:

all_sync:
  alias: Sync All Alarms
  sequence:
    - service: input_slider.select_value
      data_template: 
        entity_id: 
          -input_slider.slider1
          -input_slider.slider2
        value: "{{states.input_slider.slider3.state | float}}"

But this DID work for me

all_sync:
  alias: Sync All Alarms
  sequence:
    - service: input_slider.select_value
      data_template: 
        entity_id: input_slider.slider1
        value: "{{states.input_slider.slider3.state | float}}"    
    - service: input_slider.select_value
      data_template: 
        entity_id: input_slider.slider2
        value: "{{states.input_slider.slider3.state | float}}"

@treno - that’s done it! Thank you so much :smile:

@keithh666 and @ih8gates thanks for your help also, really appreciated.