Help with automation condition based on current state of light

I am trying to change to a light scene (which works when I click activate in HA), when I pause media, but only under the conditions that specific lights are on, at exactly 206 brightness, and rgb of 255,0,0.

I’ve tried a number of configurations (as can be seen by my commented lines), but honestly I am completely new to yaml and even the documentation is difficult to parse.

Lifx lights if that makes a difference.

From automations.yaml

  - alias: 'Family Room Media Pause switch light scene'
    trigger:
      - platform: state
        entity_id: media_player.family_room
        from: 'playing'
        to: 'paused'
    condition:
#      - condition: value_template
#        value_template: '{{ states.light.lamp.attributes.brightness == 206 }}'
      - condition: state
        entity_id: light.lamp
#        power_on: 'true'
#        rgb_color: '255,0,0'
#      - condition: state
#        entity_id: light.lamp2
        state: 'on'
#        rgb_color: '255,0,0'

    action:
      - service: scene.turn_on
        entity_id: scene.media_paused

From Dev_state
entity_id:
light.lamp

state:
on

filter attributes:
min_mireds: 111
max_mireds: 400
brightness: 206
hs_color: 0,100
rgb_color: 255,0,0
xy_color: 0.701,0.299
effect_list: lifx_effect_colorloop,lifx_effect_pulse,lifx_effect_stop
friendly_name: Lamp
supported_features: 55

you should use the template editor to see what values come from states. Also, use the states menu. Things like power_on just don’t exist on items.

seeing that you already have working code for the brightness, you can use that same line for the rgb color.

  - alias: 'Family Room Media Pause switch light scene'
    trigger:
      - platform: state
        entity_id: media_player.family_room
        from: 'playing'
        to: 'paused'
    condition:
      - condition: value_template
        value_template: "{{ states.light.lamp.attributes.brightness == 206 and states.light.lamp.attributes.rgb_color == '255,0,0' }}"
    action:
      - service: scene.turn_on
        entity_id: scene.media_paused

this is of course assuming that the rgb_color attribute returns 3 values separated by a comma inside a string. I cannot answer this because I don’t own an rgb bulb that supports this. You should be able to verify that this will work by going to the template editor and placing this code in it when your light is turned on:

{{ states.light.lamp.attributes.brightness == 206 and states.light.lamp.attributes.rgb_color == '255,0,0' }}

it should return true

{{ states.light.lamp.attributes.brightness }} 

should return 206

{{ states.light.lamp.attributes.rgb_color }}

should return the value of the rgb color.

Firstly, huge help. Simply telling me to use the editors pointed me to read up on usage of those tools, which was a huge boon to my ability to test. Being day 1 to HA, I had basically zero knowledge, and wasn’t really sure how to start.

Now that I can use template editor, I’ve found the problem. But, I’m unsure what the deal is.

Editor Values:

Brightness = {{ states.light.light_1.attributes.brightness }}
RGB = {{ states.light.light_1.attributes.rgb_color }}

Test 1 = {{ states.light.light_1.attributes.rgb_color == "255, 0, 0" }}
Test 2 = {{ states.light.light_1.attributes.rgb_color == '255, 0, 0' }}
Test 3 = {{ states.light.light_1.attributes.rgb_color == "255,0,0" }}
Test 4 = {{ states.light.light_1.attributes.rgb_color == '255,0,0' }}
Test 5 = {{ states.light.light_1.attributes.rgb_color == "(255,0,0)" }}
Test 6 = {{ states.light.light_1.attributes.rgb_color == '(255,0,0)' }}
Test 7 = {{ states.light.light_1.attributes.rgb_color == "(255, 0, 0)" }}
Test 8 = {{ states.light.light_1.attributes.rgb_color == '(255, 0, 0)' }}

Results:

Brightness = 206
RGB = (255, 0, 0)

Test 1 = False
Test 2 = False
Test 3 = False
Test 4 = False
Test 5 = False
Test 6 = False
Test 7 = False
Test 8 = False

THANK YOU!!!

Solved:

  - alias: 'Family Room Media Pause switch light scene'
    trigger:
      - platform: state
        entity_id: media_player.family_room
        from: 'playing'
        to: 'paused'
    condition:
        condition: template
        value_template: "{{ states.light.lamp.attributes.brightness == 206 and states.light.light_1.attributes.rgb_color == (255, 0, 0) }}"
    action:
      - service: scene.turn_on
        entity_id: scene.media_paused
3 Likes

Sorry, i was sleeping. Glad you got it fixed.