I have a sonoff connected to 3 physical switches and I want to use those to control 3 outlets via home assistant. The problem is the sonoff can get disconected and reconnected (power outages) and the outlets will return to their last state regardless of the state of the switch. So if switch1 is on and outlet1 is on. Then power goes out and switch1 goes off. When power returns outlet1 will be on while switch1 is off and the outlet will not turn off until the switch is switched on and then off again.
My idea is to set the outlets to match the state announced in sonoff/tele/SENSOR
. I don’t mind that it will be out of sync until the next mqtt is published. The switches are published as sonoff/tele/SENSOR {"Time":"2019-06-20T11:49:05","Switch1":"OFF","Switch2":"OFF","Switch3":"OFF"}
I tried this so far:
sensor:
- platform: mqtt
name: "Switch1"
state_topic: "sonoff/tele/SENSOR"
value_template: "{{ value_json.Switch1 }}"
availability_topic: "sonoff/tele/LWT"
payload_available: "online"
payload_not_available: "offline"
json_attributes_topic: "sonoff/tele/SENSOR"
payload_on: 'ON'
payload_off: 'OFF'
EDIT:
For some background and understanding. These switches are going to be replaced by manual thermostats (not wifi or other wireless just old fashioned contacts) if the heat turns on because the contacts closed and power is lost while contacts open when power is restored the heat will run basically forever because they need to close (too cold, but heat is on) and then reopen.