Received invalid switch is_on state: unknown. Expected: on, off, true, false

Hi,

on first boot, i always have the eror below

Received invalid switch is_on state: unknown. Expected: on, off, true, false

its normal, since the state of my switch is only known after the the harmony is connected

how can i improve this?

- platform: template
  switches:

   tv:
     value_template: "{{ states.sensor.harmony_state_tv.state }}"
     turn_on:
       - service: script.harmony_watch_tv_google
       - service: shell_command.harmony_state
         data_template:
           power: "on"
           name: "TV"
           icon: "mdi:power"
           api: "switch.tv"       
     turn_off:
       - service: script.harmony_turn_off
       - service: shell_command.harmony_state
         data_template:
           power: "off"
           name: "TV"
           icon: "mdi:power"
           api: "switch.tv"    

Read the warning box in this section

thnx for that warning box :slight_smile:

hmm; changed to below, but its still the same error?

   tv:
     value_template: "{{ states('sensor.harmony_state_tv') }}"
     turn_on:
       - service: script.harmony_watch_tv_google
       - service: shell_command.harmony_state
         data_template:
           power: "on"
           name: "TV"
           icon: "mdi:power"
           api: "switch.tv"       
     turn_off:
       - service: script.harmony_turn_off
       - service: shell_command.harmony_state
         data_template:
           power: "off"
           name: "TV"
           icon: "mdi:power"
           api: "switch.tv"

See here:

Try changing the value_template to

"{{ is_state('sensor.harmony_state_tv', 'state') }}"

Replace state with whatever that sensor’s state is when the harmony is on.

Thats it!

thnx a lot, now less error messages :slight_smile: