(Edit, go to the third post for an alternative method to getting 2 way switching working. 2 way switching is quite popular in the UK. Complete with examples. Although to use these Sonoff T1 Light switches you may need to alter your wiring…)
I have been trying to copy the setup from the post Avoiding Loops when copying light status
What I want is two wall switches to control one light.
What I have is two Sonoff T1 wall switches. One is connected to the light (sonoffLM) and the other in only powered (sonoffLS).
So when I switch ON the sonoffLS the other switch with the light attached sonoffLM will switch ON as well.
I am using the Sonoff-Tasmota firmware
I can control the individual switches on the HA web interface. So I know my mqtt setup is working and I can see the command in the terminal log on the switch.
But I just can’t get the two way switching to work as per the above example.
Can anyone see anything obvious with my code? As I am finding yaml quite a challenge.
light:
- platform: mqtt
name: "sonoffLM"
state_topic: "stat/sonoffLM/POWER"
command_topic: "cmnd/sonoffLM/POWER"
availability_topic: "tele/sonoffLM/LWT"
qos: 1
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
- platform: mqtt
name: "sonoffLS"
state_topic: "stat/sonoffLS/POWER"
command_topic: "cmnd/sonoffLS/POWER"
availability_topic: "tele/sonoffLS/LWT"
qos: 1
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
- platform: group
name: LivingRoomLights
entities:
- light.sonoffLM
- light.sonoffLS
automation:
# Control LivingRoom_lights
- alias: "sonoffLM"
initial_state: 'on'
trigger:
platform: state
entity_id: light.sonoffLM
condition:
- condition: template
value_template: '{{ (as_timestamp(now()) - as_timestamp(states.automation.sonoffLS.attributes.last_triggered | default(0)) | int > 2)}}'
action:
service_template: >
{% if trigger.to_state.state == "on" %}
light.turn_on
{% elif trigger.to_state.state == "off" %}
light.turn_off
{% endif %}
entity_id: light.LivingRoomLights
- alias: "sonoffLS"
initial_state: 'on'
trigger:
platform: state
entity_id: light.sonoffLS
condition:
- condition: template
value_template: '{{ (as_timestamp(now()) - as_timestamp(states.automation.sonoffLS.attributes.last_triggered | default(0)) | int > 2)}}'
action:
service_template: >
{% if trigger.to_state.state == "on" %}
light.turn_on
{% elif trigger.to_state.state == "off" %}
light.turn_off
{% endif %}
entity_id: light.LivingRoomLights
Thanks for any pointers you guys can provide.