Numeric_state - why no 'equal to'?

I really wouldn’t do this if I were you.
People will use it and it will all go wrong (pretty much as petro says)

    trigger:
      - platform: template
        value_template: "{{ states('sensor.s_heat_thermostat_temp') | float == 24 }}"

In this instance, the sensor could go from 23.9 to 24.7 (so is never equal to 24 and thus NEVER triggers

Just a bad idea
:man_shrugging:

The way you’re using it just use a state condition. It gets you exactly what you want:

instead of

      - condition: numeric_state
        entity_id: sensor.peloton_bpm
        above: '160'

use

      - condition: state
        entity_id: sensor.peloton_bpm
        state: '160'

But that would only trigger at 160. The API refreshes every minute so it could go from 154 to 162 and never hit 160. So I would be back to using templates similar to this?

conditions: "{{ (state_attr('sensor.peloton_username', 'Heart Rate Bpm') | int) > 160 }}"
and
conditions: "{{ (state_attr('sensor.peloton_username', 'Heart Rate Bpm') | int) >= 143 OR conditions: "{{ (state_attr('sensor.peloton_username', 'Heart Rate Bpm') | int) < 160 }}" }}"

I didn’t read your whole automation. I was simply pointing out that an “equals” numeric trigger in your case would the the same as a state trigger. Is this not what you want?

What’s the end goal of this automation? How about we start there

Alright, I read what you’re trying to do, try this automation

- alias: Change lights based on HR
  trigger:
  - platform: state
    entity_id: sensor.peloton_bpm
  condition:
  - condition: state
    entity_id: sensor.peloton_arghthor
    state: Active
  action:
  - service: light.turn_on
    data:
      rgb_color: >
        {%- set heartrate = trigger.to_state.state | int %}
        {% if heartrate >= 160 %}
          [ 255, 71, 89 ]
        {% elif 143 <= heartrate < 160 %}
          [ 252, 128, 15 ]
        {% elif 126 <= heartrate < 143 %}
          [ 250, 203, 62 ]
        {% elif 109 <= heartrate < 126 %}
          [ 182, 201, 92 ]
        {% else %}
          [ 80, 196, 170 ]
        {% endif %}

Disclaimer, this will only work in 0.118+

3 Likes

I think one solution is to include a NOT condition before the above or below numeric state.

So if the trigger state is below or equal 1, you can set trigger state as NOT above 1 instead.

1 Like

I have a slider to set a Timer for a light I have. After a given time it should turn off. If you slide the slider to “0” it also should turn off the light. That is my problem at the moment, where an “equal to” would help a lot.

that’s what template triggers are for

- platform: template
  value_template: "{{ states('sensor.xyz') == '0' }}"
1 Like

Another use-case for this.

I want a condition to check if my thermostat is set to 20. Yes I could use above 19.999 and below 20.001 but why? It would be much simpler to just have equals 20.

and you can do this, with a normal state condition

- condition: state
  entity_id: ...
  state: '20.0'

This will evaluate it as a string, so it will always return false.

- condition: state
  entity_id: ...
  attribute: ....
  state: 20.0

Without the apostrophes it will evaluate as a number.

The issue is, when setting a condition via the UI, it automatically adds the apostrophes. Combine that with the fact that numeric state doesn’t have an “equal to”, there is currently no way to do this via the UI.

Sure it’s not hard to switch to YAML mode and remove the apostrophes, but is the complete newbie to HA going to know that? Having an “equal to” in the numeric state, even if it converts to yaml as state: 20 would make things much more user friendly.

Even as an HA user for several years, I just made up an automation through the GUI and was scratching my head trying to figure out why it was evaluating as false when it was clearly true. Took me a few minutes to realize it was a string vs a number.

2 Likes

it is a string, and no, it will return true because all states are strings.

numerical_state conditions evaluate states as a number.

On my screen you’re ahead of me :). Must be ms apart. Anyways, the posts get the point across :thumbsup:

I’m not sure what I’m supposed to be retracting?

I’m saying when it was created by the GUI it would not evaluate properly. I had to switch to YAML to remove the apostrophes in order to get it to work. Which is exactly what prompted me to search and revive this old thread.

EDIT: Could the difference be that it’s a state attribute?

you just needed to write “20.0” in the state field in the UI. EDIT: You don’t even need quotes, just simply 20.0

Yes, that will make a difference

There, I added the attribute to my original post.

However my point remains the same. With no “equal to” under numerical state, and the automation editor automatically adding quotes, this is not user friendly for a new HA user who is trying to avoid YAML entirely.

Make a #feature-requests. You’re just voicing an opinion in a support thread. Posting here ultimately solves nothing other than venting frustrations.

Don’t forget that the value of a zone is an integer. There are situations where you want to check that no one is home (zone.home == 0) or someone is alone at home (zone.home == 1).

yes that did the trick thanks:
I want to confirm power consumption is zero


condition: state
entity_id: sensor.socket2_power
state: '0.0'