Simply "above or equal" conditions

Hello.
I have one input field - target temperature. Additional object “myroomtargettemp”. In all automations it appears as “myroomtargettemp”.
So, I want to make two conditions.

  1. switch off some Switch when sensor_temp is below myroomtargettemp. This condition is simple, I solved it via numeric_state.
  2. swith on some Switch when sensor_temp is above or equal to myroomtargettemp.
    And it is really crash.
    Please, help me to write this simple condition.
    Numeric_state has only above and below conditions.
    I read that state condition can help, but I see only state = some fixed string or number. But I want a condition with a variable myroomtargettemp.
    How can I do that? Thanks.

Can you clarify what you mean by “object ‘myroomtargettemp’” and “variable myroomtargettemp”? Also, please post your automation so we can see what you have tried and how it is structured.

You could also create a simple thermostat through hacs:

Here is one of my fireplaces

image

I hope this helps.

It’s not only thermostat, it’s a part of another automation. But it must works as I wrote.
“myroomtargettemp” - it’s “input_number.myroomtargettemp”.
So I simply need a condition “if sensor <= input_number.myroomtargettemp”. How can I do that without HACS or another additional components, just with standard language? And I have no desire to rewrite whole automation. “<=” is very simple, why I can’t do that in HA standard terms? For now I must hold two input_numbers: for above and below conditions. But when temperature or another parameter stays at edge value - automation doesn’t work because, e.g. “24 is below 24,5 and 25 is above 24,5” - good, but “24,5 is not above and not below 24,5, it’s equal”.The problem is that I need some actions when it stays at 24,5 (or another value in input_number.myroomtargettemp), but I can’t call it because no conditions with “equal to input_number.myroomtargettemp”.
So many words for simple thing. How can I make a “if sensor <= input_number.myroomtargettemp”?

There are multiple ways to do this, here are three methods…

Using a State trigger with two conditions:

trigger:
  - platform: state
    entity_id: sensor.YOUR_SENSOR
    not_from: unknown
condition:
  - or:
      - alias: Are they Equal?
        condition: state
        entity_id: sensor.YOUR_SENSOR
        state: input_number.myroomtargettemp
      - alias: Is sensor lower?
        condition: numeric_state
        entity_id: sensor.YOUR_SENSOR
        below: input_number.myroomtargettemp

Using Numeric State Trigger with template:

trigger:
  - platform: numeric_state
    entity_id: sensor.YOUR_SENSOR
    above: 0
    value_template: "{{ (states('input_number.myroomtargettemp') | float(0)  + 0.01) - state.state | float  }}"
You can approach the comparison from either direction
trigger:
  - platform: numeric_state
    entity_id: sensor.YOUR_SENSOR
    below: 0
    value_template: "{{ ( state.state | float - 0.01) - (states('input_number.myroomtargettemp') | float(0)}}"

Using Template Triggers:

trigger:
  - platform: template
    value_template: |-
      {{ states('sensor.YOUR_SENSOR') | float(0) <=
      states('input_number.myroomtargettemp') | float(0) }}

Templating Docs:
Templating
Template Trigger
Template Condition

I already tried this. But condition doesn’t wotk, in trace it says “wanted input_number.myroomtargettemp”, state “24.5”.
It treats “input_number.myroomtargettemp” as string (treats just as words “input_number.myroomtargettemp”, not as value of this input_number.myroomtargettemp).
What I doing wrong?

Post your automation and we can have a look.

Sorry, I checked my automation. I copied object ID like myroomtargettemp without input_number. My mistake. input_number.myroomtargettemp works like a charm. Thank you guys.

1 Like

In HA all states are strings. It is definitely possible to run into issues doing string comparisons the way the State condition option does, especially if your sensor is from a custom integration. Of the options I posted, I find Template triggers to be the easiest to understand.