IF condition comparing two values

I am trying to make an automation like this:
If sensor1 < attribute1-sensor1*1,05 turnXon, else trunXoff.

Is there an easy way of accomplishing this?

You will need to use a Template as the condition.

1 Like

Yes I get that. I have this at the moment but it does not work at all:
'{{ float(states('sensor.electricity_price_vargstigen_9')) > 1.5 * float(state_attr('sensor.electricity_price_vargstigen_9', 'avg_price')) }}'
If I use it in Developer tools/templates I get the True and False etc but in the automation it never pass.

Post the automation containing the template.

1 Like

Sure:

alias: Electric price on off water heat
description: ""
trigger:
  - platform: time_pattern
    minutes: "22"
condition:
  - condition: template
    value_template: >
      '{{ float(states('sensor.electricity_price_vargstigen_9')) > 1.5 *
      float(state_attr('sensor.electricity_price_vargstigen_9', 'avg_price'))
      }}'
    enabled: true
action:
  - device_id: 0cc164d9a56d93fcce5d91eafaa76ead
    domain: mobile_app
    type: notify
    title: Electricity price
    message: Priset är nu för högt!
mode: single

Remove the template’s outer single-quotes.

condition:
  - condition: template
    value_template: >
      {{ states('sensor.electricity_price_vargstigen_9') | float(0) > 1.5 *
        state_attr('sensor.electricity_price_vargstigen_9', 'avg_price') | float(0) }}
    enabled: true
1 Like

Why is this post under blueprints?? :thinking:

I just did, now it works, thank you!

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.

1 Like