Template switch turns ON at OFF action

It’s all on one board.

It’s this board: Relay Module 16 Channel Wifi Remote Control Development Board DC 24V For ESP8266 Secondary Development Learning Smart Home Wireless Control : Amazon.nl: Business, Industry & Science

ChatGPT always say something.
Anyway, according to log esp was not crashing and relay powering/hardware issues don’t make turn_off command becoming turn_on…

or turn them on/off via script

That’s worth to try.

yes, this is it!

Had to add optimistic too with true as value, but this makes it work.

Thanks!

You both did! thanks a lot!

Removed the delay, @Karosm is correct, without the delay it works fine now too. I still cannot explain it fully, but it works.

Glad to hear

1 Like

If you have patience to play, try the on_turn_on as well like Pafcas suggested. There is probably some difference how it updates.

Unfortunately the documentation is far from the quality that Esphome has.

  • optimistic (Optional, boolean): Whether to operate in optimistic mode - when in this mode, any command sent to the template switch will immediately update the reported state. Defaults to false.

Yes, that’s what I did. I now have “on_turn_on” and “on_turn_off”. I’ll try and see if the turn_on_action and turn_off_action work with optimistic too.

both work with optimistic set to true. So doesn’t matter if I use on_turn_off or turn_of_action. With optimistic set to true it just works.

1 Like

Remains mystery to me how “Optimistic” was needed to turn off, but not to turn on…
If somebody can explain or have an idea, very much welcome!

The funny thing is with on_turn_on/off I got an error message saying I needed to use optimistic. Didn’t get that with turn_on/off_action. Oh well, working now and going to figure out how to use smart_thermostat or generic_thermostat. Again; many thanks to you guys.

Do you have it to post here?

I can get that tomorrow. Have to rewrite the code again, but I have been summoned by my wife. :wink:

Appreciate that!

Only when I edit turn_off_action to on_turn_off, it results in the error:

INFO ESPHome 2024.12.2
INFO Reading configuration /config/esphome/vloerverwarming.yaml...
Failed config

switch.template: [source /config/esphome/vloerverwarming.yaml:59]
  
  Either optimistic mode must be enabled, or turn_on_action or turn_off_action must be set, to handle the switch being set.
  platform: template
  name: Vloerverwarming - Woonkamer
  on_turn_on: 
    - switch.turn_on: relay_woonkamer_1
    - switch.turn_on: relay_woonkamer_2
    - switch.turn_on: relay_woonkamer_3
    - switch.turn_on: relay_woonkamer_4
    - switch.turn_on: relay_woonkamer_5
    - switch.turn_on: relay_woonkamer_6
  on_turn_off: 
    - switch.turn_off: relay_woonkamer_1
    - switch.turn_off: relay_woonkamer_2

Just editing turn_on_action to on_turn_on doesn’t preset the error.

I thinking about your problem,and i have a question: Why you use template switch? why dont use thermostat to turn on/off relays? And optimistic needs becouse template switch dos not have state,so esphome dosnt know,is the tempalte switch on or off.

Also a very good question… I’ll have to look into this. I’m using Smart Thermostat, at least, that’s the idea, to automate everything based on external temp. sensors. But 'll look into the thermostat from ESPhome.