Trying to turn on cooling based on temperature state

alias: "High Temperature "
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.thermostat_temperature
    for:
      hours: 0
      minutes: 0
      seconds: 3
    above: "72"
    below: "78"
condition: []
action:
  - device_id: 36e04ece7c7a80d4e2753da280c62ecf
    domain: climate
    entity_id: climate.thermostat
    type: set_hvac_mode
    hvac_mode: cool
  - service: climate.set_temperature
    data:
      temperature: 68
    target:
      device_id: 36e04ece7c7a80d4e2753da280c62ecf
mode: single

This is the automation Iā€™ve made but when a state change occurs in the numeric value (up or down) the automation does not fire. What am I doing wrong?

Looks like your trigger will fire when the temperature goes up from 71 to 72 or down from 79 to 78. Is that what you want?

Ahhh okay no its not really I was playing around with it as it seemed not to be working. Ideally Iā€™d want it to be where if the temp goes above 78 itā€™s cuts on. So to properly test it Iā€™d need to set the above value to 78 and let the temp go over it?

I was confused on this part as I thought that if when the state changed, if it was above the desired number regardless if coming down from like 79 to 78.7 it would then trigger it as a state change occurs and the value is above the number.

So in actually if I want it that way it needs to go from like 77 to 78 to cross the threshold?

Sorry still kinda new to some of the logic used here, and I appreciate yā€™allā€™s help

Which attribute should I be selecting here? Nothing specific for current temperature. I just left it blank as I was unsure

Had to upload the second pic as a separate post

None of them, if youā€™re only concerned with temperature.

I suspect itā€™s the problem with string and number:

but how do you fix it?

Is there really an attribute on that entity called temperature? I suspect youā€™ve put ā€œtemperatureā€ in the attribute box but you donā€™t know why. Leave it blank unless you know what youā€™re doing.

You can use to: "18" but that might not achieve what you want.

What are you trying to do here?

No, itā€™s a reading of a thermostat through a template. Itā€™s a number in degr. Celsius. It doesnā€™t work without the attribute either.

Im trying to trigger something when a certain temperature on a thermostat has been selected.

What does Developer Tools / States show for that entity? If itā€™s something like "18.0" then thatā€™s not the same as "18".

Options:

  1. Use a numeric state filter:
- trigger: numeric_state
  entity_id: sensor.xxx
  above: 18
  1. Use a template binary sensor helper:
{{ states('sensor.xxx')|float(0) >= 18 }}

and trigger off that:

- trigger: state
  entity_id: binary_sensor.xxx
  to: 'on'
  1. Trigger off all changes, use a condition:
triggers: 
  - trigger: state
    entity_id: sensor.xxx
conditions:
  - condition: numeric_state
    entity_id: sensor.xxx
    above: 18


I understand that, I was hoping I could be using the function to compare numbers rather than strings.
I also looked at the binary sensor approach yesterday but couldnā€™t get the systax right and HA documentation donā€™t tell me much or I donā€™t know where to look.
In short, ā€˜stateā€™ canā€™t compare numbers, right?

Not in the way that you might expect, no.

Template a binary sensor:

image

then, replacing xxx with the entity ID Iā€™m not going to try to copy from the screenshot above:

That will give you binary_sensor.hot, and you can trigger off that.

Thanks man.

1 Like
alias: Test of state function_1
description: ""
triggers:
  - trigger: template
    value_template: "{{ states('sensor.baterkovy_thermostat_set_temperature')|float(0) == 18 }}"
conditions: []
actions:
  - type: turn_off
    device_id: bbc00cce5c3f8fd33033b88140e2b457
    entity_id: 223e109cad1123870e65acac9959fbae
    domain: switch
mode: single

This works. I really need something to happen when x=y.
Not >= or anything else. But thanks for your help with the syntax.
P.

You canā€™t reliable compare a float to an int (or a hard-coded float) (not a HA limitation, each computer language suffers with that)

So try this

   value_template: "{{ states('sensor.baterkovy_thermostat_set_temperature')|int(0) == 18 }}"

But what If I want to have the trigger valve 18,1? Or a value of another sensor, or variable?
I have the entity sensor.baterkovy_thermostat_set_temperature
defined as float(1) template, so, Iā€™m guessing it is a number.
The script works with int as well as real numbers.
Now Iā€™m working on value template that exactly compares values of two entities. The HA swallows the code but doesnā€™t triggerā€¦

alias: Test of states function_1
description: ""
triggers:
  - trigger: template
    value_template: >-
      "{{ states('sensor.baterkovy_thermostat_set_temperature') == 
      states('sensor.baterkovy_termostat_current_temperature') }}"
conditions: []
actions:
  - type: turn_off
    device_id: bbc00cce5c3f8fd33033b88140e2b457
    entity_id: 223e109cad1123870e65acac9959fbae
    domain: switch
mode: single