I have a tuya LED light and an ESPhome switch on an LCD touch screen.
The switch toggles and show state and so does the light.
I want them to mirror each other because the switch can be used to turn on the light but the light could be turned on some other way and I want the lights state to show on the switch.
This is the switch and the light I have.
switch.480screen_button_switch
light.lumary_smart_rgbai_outdoor_spot_light_a2
I found this code but it’s for two switches not a switch and a light. Is there are better way to do this??
- alias: kitchen
trigger:
- platform: state
entity_id: switch.480screen_button_switch, light.lumary_smart_rgbai_outdoor_spot_light_a2
from: 'on'
to: 'off'
- platform: state
entity_id: switch.480screen_button_switch, light.lumary_smart_rgbai_outdoor_spot_light_a2
from: 'off'
to: 'on'
action:
service_template: '{% if trigger.to_state.state == "on" %} light.turn_on {% elif
trigger.to_state.state == "off" %} light.turn_off {% endif %}
'
data_template:
entity_id: '{% if trigger.from_state.entity_id == "switch.480screen_button_switch" %} light.lumary_smart_rgbai_outdoor_spot_light_a2
{% elif trigger.from_state.entity_id == "light.lumary_smart_rgbai_outdoor_spot_light_a2" %} switch.480screen_button_switch
{% endif %}'