I’ve setup a Sonoff relay (stock firmware) that is operating in inching mode to control and turn on/off an air conditioner.
The Sonoff switch turns on for a second, then switches back off. Unfortunately, I don’t know what state the air con is in, whether it is operating and on, or if it’s off.
What I want to do is create a virtual switch that remembers the current state, so that it operates like a more traditional on/off switch, and ideally control it via Google Home. I don’t have any other sensor (yet) to determine the current state.
I’m very new to Home Assistant, but from what I’ve read I think I need to create an input boolean and also create a template switch.
# AC State Boolean
input_boolean:
ac_state:
name: Current AC State
icon: mdi:air-conditioner
# AC Virtual Switch
switch:
- platform: template
switches:
ac_switch:
friendly_name: Air Conditioner
value_template: >-
{% if is_state('input_boolean.ac_state', 'on') %}
'on'
{% elif is_state('input_boolean.ac_state', 'off') %}
'off'
{% else %}
'unavailable'
{% endif %}
turn_on:
service: switch.turn_on
data:
entity_id: switch.sonoff_1000df4b41_4
turn_off:
service: switch.turn_on
data:
entity_id: switch.sonoff_1000df4b41_4
The config above is turning the air con on and off, but still the state is not being maintained. It’s behaving similar to the physical switch and turn off shortly after I turn it on.
I’m sure this is simple but I have no idea what I might be missing.
1 post - 1 participant