I need help mirroring an rgbw tuya bulb to a virtual switch

Solved it myself. This is how I got it work. I couldn’t let both switches mirror each other when changing colors or else it would go into a loop.

- alias: Mirror Master Light Color

initial_state: 'on'

trigger:

platform: state

entity_id: light.master_light

condition:

condition: template

value_template: "{{ trigger.to_state.state != 'off' }}"

action:

service_template: light.turn_on

entity_id: light.masterlight

data_template:

brightness: '{{states.light.master_light.attributes.brightness |int}}'

rgb_color: [

'{{states.light.master_light.attributes.rgb_color[0] |int}}',

'{{states.light.master_light.attributes.rgb_color[1] |int}}',

'{{states.light.master_light.attributes.rgb_color[2] |int}}'

]

- alias: Mirror Master Light On 1

initial_state: 'on'

trigger:

platform: state

entity_id: light.masterlight

to: "off"

action:

service: light.turn_off

entity_id: light.master_light

- alias: Mirror Master Light On 2

initial_state: 'on'

trigger:

platform: state

entity_id: light.master_light

to: "off"

action:

service: light.turn_off

entity_id: light.masterlight

- alias: Mirror Master Light Off 1

initial_state: 'on'

trigger:

platform: state

entity_id: light.masterlight

to: "on"

action:

service: light.turn_on

entity_id: light.master_light

- alias: Mirror Master Light Off 2

initial_state: 'on'

trigger:

platform: state

entity_id: light.master_light

to: "on"

action:

service: light.turn_on

entity_id: light.masterlight

/r/homeassistant Thread