Help to use a attribute as trigger

I have a sensor for my electricity price for my home. I want to check the price level and if the price is high, I will turn off the heater to my Spa (small swimming pool).

One attribute in the sensor is called “price_level”. If state is_not “very_expencive” on pric level I want the heator to be on.

I have wrote this but it don´t work.

- alias: Spa
  trigger:
    - platform: template
      entity_id: sensor.electricity_price_rydbovagen_16
      value_template: "{{ not is_state('price_level', 'very_expencive') }}" # Heater and pump starts if attribute is_not "very_expencive"

  action:
    service: homeassistant.turn_on
    entity_id: 
         - switch.pump_spabad          # turn on pump and heater

Skärmklipp

Use is_state_attr(...), also double check the spelling and capitalization on “very_expencive”… If it is all caps like “VERY_CHEAP” is in your screen shot, it needs to be all caps in your template.

alias: Spa
  trigger:
    - platform: template
      value_template: "{{ not is_state_attr('sensor.electricity_price_rydbovagen_16', 'price_level', 'very_expencive') }}"
  action:
    service: homeassistant.turn_on
    entity_id: 
         - switch.pump_spabad
1 Like

Note that HA is case sensitive, VERY_EXPENSIVE is different from very_expensive. Here’s one way of triggering every time the attribute changes and it’s not to VERY_EXPENSIVE

- alias: Spa
  trigger:
    - platform: state
      entity_id: sensor.electricity_price_rydbovagen_16
      attribute: price_level
  condition:
    - condition: not
      conditions:
        - condition: state
          entity_id: sensor.electricity_price_rydbovagen_16
          attribute: price_level
          state: 'VERY_EXPENSIVE'
  action:
    - service: switch.turn_on
      entity_id: 
        - switch.pump_spabad          # turn on pump and heater
1 Like

Thanks. It works :slight_smile: