Using a state attribute in notifications

Hi there!

I have a given automation that looks like this:

alias: Preisänderung bei Tibber
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.electricity_price_xxx
    attribute: price_level
condition: []
action:
  - device_id: 045xxx
    domain: mobile_app
    type: notify
    message: >-
      Der Strompreis ist gerade von {{ trigger.from_state.state }} zu {{
      trigger.to_state.state }} gewechselt.
    title: Preisänderung bei Tibber
mode: single
  • “sensor.electricity_price_xxx” contains the actual price,
  • its attribute “price_level” if the current price level is “normal”, cheap", “expensive”, etc.

Using the automation above, the price itself is returned, but I’d need the price_level instead. Can somebody guide me how this can be accomplished?

Thanks in advance!

Try this:

message: >-
      Der Strompreis ist gerade von {{ trigger.from_state.attributes.price_level }} zu {{
      trigger.to_state.attributes.price_level }} gewechselt.

That did the trick. Thanks a lot!

1 Like