Test if two values are equal in a automation

I have Tibber for electricity and the current price is in ‘sensor.electricity_price’. They lowest price of the day is in ‘sensor.electricity_price’ atribute ‘min_price’.

In the ‘Then do’ of my automation, I want to do a simple condition, to see if the current price equals the lowest of the day;

              - condition: state
                entity_id: sensor.electricity_price
                attribute: min_price
                state: sensor.electricity_price

But this doesn’t work, it evaluates the state as a string, not a value;

              ## if/condition/0/entity_id/0
              
              Executed: August 2, 2024 at 19:13:39
              Result:
              
              result: false state: 0.217 wanted_state: sensor.electricity_price

Help is appriciated!

I’ve tried things with numeric state, that does evaluates both virables correctly, but does’t offer ‘equals’.

You will need to use a Template condition.

- condition: template
  value_template:  |
    {{ state_attr('sensor.electricity_price', 'min_price') | float == states('sensor.electricity_price') | float }}

EDIT: Corrected value for condition

1 Like

Thanks, when I try that, I get;

Message malformed: extra keys not allowed @ data[‘action’][0][‘then’][0][‘else’][0][‘if’][0][‘value_template’]

Sorry, I forgot to change the condition type… I’ve corrected it above… :man_facepalming:

I think this

 float == state('sensor.electricity_price')

should be;

 float == states('sensor.electricity_price')

Right?

1 Like

I’ve tested it, and it should be;

- condition: template
  value_template:  "{{ state_attr('sensor.electricity_price', 'min_price') | float == state('sensor.electricity_price') | float }}"

Kudo’s for Didgeridrew! thanks for your help, please correct you answer, I’ll mark it as the correct answer.

Thnx