Using templating condition to check if a trigger.to_state attribute is empty/null/missing/etc

Goal: I’m trying to have a condition using the trigger.to_state to check if the to_state attribute includes color instructions for a light and if it does to not continue with the automation, but if it doesn’t include color instructions to continue with the automation.
The automation action is to set the brightness and color temperature to a default when the light is turned on normally, but I don’t want it to run if the light is turned on with a color instruction. This may happen when you tell Alexa to turn on the light to “crimson”, instead of just turning the light on. (See example event for each scenario below)

Current state of the automation: The trigger and the actions work.

What I’ve tried:
I’ve tried various Conditions attempting to combine instructions from these two posts:

This says I should be able to see if the attribute I want (in this case rgb_color) is empty/null/missing/etc.

This says that i should get the attribute list of the new state attributes by using state_attr(‘trigger.to_state’, ‘rgb_color’) or something like that.

What I tried but didn’t work:

condition: template
value_template: >-
  {% if trigger.to_state.attributes.rgb_color is defined %}False{% else %}True{%
  endif %}

I’ve also tried

condition: template
value_template: >-
  {{ trigger.to_state.attributes.rgb_color != None }}

And tried this

condition: template
value_template: >-
  {% if state_attr('trigger.to_state', 'rgb_color') == None %}False{% else
  %}True{% endif %}

What am I doing wrong?

The complete automation:

alias: Bulb toggle set to default (Soft White) (BP upgrade)
description: a description
trigger:
  - platform: state
    entity_id: light.living_room_lamp_right
condition:
  - condition: template
    value_template: >-
      {% if trigger.to_state.attributes.rgb_color is defined %}False{% else
      %}True{% endif %}
action:
  - choose:
      - conditions:
          - condition: template
            value_template: '{{ trigger.from_state.state == ''off'' }}'
        sequence:
          - service: light.turn_on
            data:
              color_temp: 370
              brightness: 255
              entity_id: light.living_room_lamp_right
    default: []
mode: parallel
max: 100

Example Events:
This should trigger the automation
You can see in new_state attributes that there are not color values like xy_color, rgb_color, and xy_color

{
    "event_type": "state_changed",
    "data": {
        "entity_id": "light.living_room_lamp_right",
        "old_state": {
            "entity_id": "light.living_room_lamp_right",
            "state": "off",
            "attributes": {
                "min_mireds": 154,
                "max_mireds": 500,
                "off_brightness": null,
                "friendly_name": "Living Room Lamp Right",
                "icon": "mdi:floor-lamp",
                "supported_features": 59
            },
            "last_changed": "2021-01-18T16:11:46.883780+00:00",
            "last_updated": "2021-01-18T16:11:46.883780+00:00",
            "context": {
                "id": "f273334cf84603659777e16b7563d91f",
                "parent_id": null,
                "user_id": "af282cb2b56a49718a9eaa7336fc52d9"
            }
        },
        "new_state": {
            "entity_id": "light.living_room_lamp_right",
            "state": "on",
            "attributes": {
                "min_mireds": 154,
                "max_mireds": 500,
                "brightness": 254,
                "color_temp": 370,
                "off_brightness": null,
                "friendly_name": "Living Room Lamp Right",
                "icon": "mdi:floor-lamp",
                "supported_features": 59
            },
            "last_changed": "2021-01-18T16:11:52.924514+00:00",
            "last_updated": "2021-01-18T16:11:52.924514+00:00",
            "context": {
                "id": "12f4868c703ae4203c9e800167bdd267",
                "parent_id": null,
                "user_id": "af282cb2b56a49718a9eaa7336fc52d9"
            }
        }
    },
    "origin": "LOCAL",
    "time_fired": "2021-01-18T16:11:52.924514+00:00",
    "context": {
        "id": "12f4868c703ae4203c9e800167bdd267",
        "parent_id": null,
        "user_id": "af282cb2b56a49718a9eaa7336fc52d9"
    }
}

This should NOT trigger the automation
You can see in new_state attributes that there are color values like xy_color, rgb_color, and xy_color

{
    "event_type": "state_changed",
    "data": {
        "entity_id": "light.living_room_lamp_right",
        "old_state": {
            "entity_id": "light.living_room_lamp_right",
            "state": "on",
            "attributes": {
                "min_mireds": 154,
                "max_mireds": 500,
                "brightness": 254,
                "color_temp": 370,
                "off_brightness": null,
                "friendly_name": "Living Room Lamp Right",
                "icon": "mdi:floor-lamp",
                "supported_features": 59
            },
            "last_changed": "2021-01-18T16:11:52.924514+00:00",
            "last_updated": "2021-01-18T16:11:52.924514+00:00",
            "context": {
                "id": "12f4868c703ae4203c9e800167bdd267",
                "parent_id": null,
                "user_id": "af282cb2b56a49718a9eaa7336fc52d9"
            }
        },
        "new_state": {
            "entity_id": "light.living_room_lamp_right",
            "state": "on",
            "attributes": {
                "min_mireds": 154,
                "max_mireds": 500,
                "brightness": 254,
                "hs_color": [
                    347.94,
                    91.284
                ],
                "rgb_color": [
                    255,
                    22,
                    69
                ],
                "xy_color": [
                    0.658,
                    0.284
                ],
                "off_brightness": null,
                "friendly_name": "Living Room Lamp Right",
                "icon": "mdi:floor-lamp",
                "supported_features": 59
            },
            "last_changed": "2021-01-18T16:11:52.924514+00:00",
            "last_updated": "2021-01-18T16:12:53.150930+00:00",
            "context": {
                "id": "52791494972feabaf1a439d804728cab",
                "parent_id": null,
                "user_id": "40aa582d109c4e999e21c6956b29442e"
            }
        }
    },
    "origin": "LOCAL",
    "time_fired": "2021-01-18T16:12:53.150930+00:00",
    "context": {
        "id": "52791494972feabaf1a439d804728cab",
        "parent_id": null,
        "user_id": "40aa582d109c4e999e21c6956b29442e"
    }
}
1 Like
condition: template
value_template: >-
  {{ trigger.to_state.attributes.rgb_color is not defined }}

Should return true, if attribute ‘rgb_color’ is not defined.

When this color light is on it will always have an rgb_color attribute. The only time it won’t is when it’s off. You can confirm it by inspecting the light’s attributes in Developer Tools > States.

So when it’s on, checking if rgb_color is defined will always evaluate to true. It’s always defined when the light is on.