If My Tea Maker Is In "Brewed" State, Turn On Lights

Is there a way to get the state_detail from switch.coffee_maker? I tried my automation template:

  - alias: "Coffee Brewed - Turn On Lights"
    trigger:
      platform: template
      value_template: "{% if is_state('states.switch.coffeemaker.attributes.state_detail', 'Brewed') %}true{% endif %}"
    action:
      service: light.turn_on
      entity_id: light.living_room_floor_lamps
      data:
        brightness: 255

And it did nothing until I open up “Coffee Brewed” (actually, I made tea) and clicked in “Trigger” link. Then the light will turn on, but it does not look like the template trigger happens automatically.

What would be the solution if I want to use attributes instead of determining on/off states?

Update: OH! Maybe I should use is_state_attr as listed in documentation:

Somehow, I glanced over that. Will try it again the next day. Maybe I could change “Brewed” to “Refill” and see how that works.

Okay everyone. Here’s the code that worked!

automation: # Wanted to add the "automation" tag for completeness.
  - alias: "Tea Brewed - Turn On Lights"
    trigger:
      platform: template
      value_template: "{% if is_state_attr('switch.coffeemaker', 'state_detail', 'Brewed') %}true{% endif %}"
    action:
      service: light.turn_on
      entity_id: light.living_room_floor_lamps
      data:
        brightness: 255

Would like to contribute my code in “Share My Projects,” but forgot that I have a thread here in the Configurations forum.

Could others try my code to make sure it works, replacing any entity IDs with your own? Sometimes I’ll need a second set of testers.