Problems new switch template

Hey guys - so I just tried creating my first switch template and its a good ol’ bowl o’ fail. I am using the ISY994 component to import an iolinc (integrated binary sensor and on/off switch) to control my garage door. According to the HA frontend template editor, I am getting true/false from the sensor; however when I start HASS, I get the following:

17-03-03 04:36:55 ERROR (MainThread) [homeassistant.components.switch.template] Received invalid switch is_on state: none. Expected: on, off, true, false

My switch config is in separate file from my configuration.yaml
switch: !include conf/switches.yaml

In the actual file, I have:

- platform: template
    switches:
      garage:
        value_template: "{{ is_state('binary_sensor.sensorgarage_door__new',  'on') }}"
        turn_on:
          service: switch.turn_on
          entity_id: switch.garage_door__newrelay
        turn_off:
          service: switch.turn_off
          entity_id: switch.garage_door__newrelay

I have checked and all my entity IDs are correct and show true/false or on/off in the UI :frowning:

Here are some screenshots that may help…

After reading some forum posts, I am no further along. Many posts show a different way to query the status of the binary sensor using the states.binary_senor notation, but that didnt help :frowning:

Could you try moving back 2 spaces everything below your - platform: template line

the s in switches: should line up with the p in platform: I believe.

Everything else appears right to me

When you start HASS, the entity doesn’t exist yet, thus the error evaluating the value_template.

See if this helps:

Yea, that must have been some mess up in my copy and paste… because you are right, but my actual config does have the spacing correct… on that note, I hate YAML… :wink:

Ahhh… yes, that explains it… ok so dumb question, if the entity doesnt exist when HASS first starts, does it check again at some point? If so, when? I ask because I’m not sure how to handle this. The thread you pointed to says to add some conditions, but I think that just avoids the error - not ensuring the switch is properly created…

Thanks

I think it works best if you specify a related entity_id, too. The sensor is re-evaluated when the entity’s state changes.

So when HASS restarts, until the state changes, it doesnt know the state? Even if it pulled it from the SQLite db, it could be no longer valid… That would suck…

And,sorry - what do you mean it would work best if I used a related entity_ID?

I’m pretty sure that the template gets re-evaluated when the state of the supplied entity_id changes. Not 100% sure, tho.