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

Note on State condition: The state option accepts the entity ID of helper entities (also known as input_* entities). The condition will pass if the state of the entity matches the state of the given helper entity. This method does not work with entities from all domains.

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.

Why doesn’t condition equal exist, only above and below?

The State condition is “condition equal”.

Hm, alright. But would it also be possible doing:

condition: and
conditions:
  - condition: numeric_state
    entity_id: sensor.YOUR_SENSOR
    below: input_number.myroomtargettemp
  - condition: not
    conditions:
      - condition: numeric_state
        entity_id: sensor.YOUR_SENSOR
        above: input_number.myroomtargettemp
        below: input_number.myroomtargettemp

I’ve never used that, but it should work.

1 Like

Didgeridrew & sonite
First of all thank you for pointing me in the right direction. I’m a noob in yaml codes and not really interrested in it. The reason I use the visual editor in home assistant only.

Above or equal exist in the visual editor, I use it for my zone heating in the house,
Each room has a helper to set the target temperature, each room is equiped with a temperature sensor by ESP home ( wemos mini “Huis temp”)
This is the script with conditions to allow switch off "CV uit / boiler off " only if no zone is demanding heat.
Translation: slaapkamer voor = sleeping room front of the house

The visual editor in two steps:



Repeat for other zones
As you can see: If a treshold is NOT above or below the sensor value it means it is EQUAL
It works perfect

What you have posted is exactly what @sonite posed in their second example.

While I understand the sentiment of not being interested in YAML as a new user, it is the only efficient method for sharing and editing HA configuration. That is why the Question Guidelines for this forum expressly state to not use screenshots for things that can be shared as text.

Didgeridrew,

Read the guidelines and dived a litle more in YAML, result understand your point. Second: I replied earlier before testing fully, woke up next morning with a faulty heating system and my wife high in the curtains.
I tried to copy paste sonite’s code again, as already stated I’m a noob in YAML, 2 hours trial with all kind of additions without succes. After sufficient coding & testing in visual editor it was finally working with some small but effective changes resulting in the next (yes YAML ):

alias: above OR equal
sequence:
  - if:
      - condition: or
        conditions:
          - condition: numeric_state
            entity_id: input_number.sensor_your_sensor
            below: input_number.input_number_myroomtargettemp
            enabled: true
          - condition: not
            conditions:
              - condition: or
                conditions:
                  - condition: numeric_state
                    entity_id: input_number.sensor_your_sensor
                    enabled: true
                    above: input_number.input_number_myroomtargettemp
                  - condition: numeric_state
                    entity_id: input_number.sensor_your_sensor
                    below: input_number.input_number_myroomtargettemp
                    enabled: true
    then: []
    enabled: true
description: "Condition "
icon: mdi:sigma