Using an Attribute for And If in Automations?

I tried to use the attribute off_peak_1 for an automation
this syntax on bold beyond did not work
even as a helper complained about not being a float
any idea to use this value here?

above: {{ state_attr(‘sensor.stohmisch_strompreis’, ‘off_peak_1’) }}

cheers
chriz

alias: Strom teuer
description: ""
triggers:
  - minutes: "2"
    trigger: time_pattern
conditions:
  - type: is_value
    condition: device
    device_id: 5cd46bc8adce56e1bc45b91d4ce9b6cc
    entity_id: 99b9062165f909b755eae8e35d438ad3
    domain: sensor
    **above: above: {{ state_attr('sensor.stohmisch_strompreis', 'off_peak_1') }}**

actions:
  - data:
      message: Strom teuer, lade Batterie nicht mehr
      target: "#HomeAssistant:matrix.sysops.de"
    action: matrix.send_message
  - device_id: 1f723340d8e5b4128b0ee801bd489bd5
    domain: number
    entity_id: ff51026cf7e6b067eb3aa09c877e160d
    type: set_value
    value: 15
mode: single

Hi Christian,

Templates don’t work with Device_id addressing. Use entity_id addressing instead.

As stated above, templates are not supported in Device conditions. However, attributes cannot be accessed in the comparand of Numeric state conditions either…

You have a couple options:

  1. Use a Numeric state condition but invert the setup so you can access the attribute:
condition: numeric_state
entity_id: sensor.stohmisch_strompreis
attribute: off_peak_1
below: sensor.EXAMPLE
  1. Use a Template condition:
condition: template
value_template: |
  {{ states('sensor.EXAMPLE') | float(0) > state_attr('sensor.stohmisch_strompreis', 'off_peak_1') }}

There are other option as well, such as adding a value_template to a Numeric state condition or creating a Template sensor to hold the value from the attribute in a state. But the options above are simpler.