How to trigger automaton by temperature

Hi,

I have two thermostats, “climate.upstairs” and “climate.downstairs”

I’d like to be able to set a trigger in an automation when “current_temperature” goes above (or below) a specific number.

Struggling to get the “state” and/or platform correct. Something like this:

-alias: Thermostats Trigger
trigger:
platform: climate
entity_id: downstairs.current_temperature
above: 72

This obviously doesn’t work, but I’ve played with all kinds of things like numeric_state, state, etc…

Any help?

Thanks.

1 Like

It might be that the temperature is exposed through a sensor. Have you looked through your entity list so you are working with the correct entity_id? Also it looks weird that it would be downstairs.current_temperature, the entities usually start with a device type, e.g. light, sensor, etc… But take it for what it is from a guy that doesn’t have any thermostats :slight_smile:

/R

I set up a fan on a wifi powerpoint to be triggered in my kitchen a few days ago. See below. You need a state, and as far as I am aware the single quotes around the above value ‘72’ - I’m in Australia so temperature is reversed.

alias: Kitchen Hot
trigger:
  platform: numeric_state
  entity_id: sensor.kitchen_temperature_2_1
  above: '27'
action:
  service: switch.turn_on
  entity_id: switch.switch_05
1 Like

Thanks Robban…

That’s just it - I know downstairs.current_temperature isn’t correct. Trying to figure out what might be. “current_temperature” is an attribute of “downstairs” which is of type “climate”. There’s no “sensor” that I can find associated with my thermostats, which is what I believe I should be looking for here.

Maybe this helps:

I’m trying to trigger on the ‘current_temperature’ attribute here.

I am able to SET the ‘target’ temperature with ‘climate.set_temperature’ as follows:

service: climate.set_temperature
data:
entity_id: climate.downstairs
temperature: 75
.

Maybe a value template would work here?

{{ states.climate.downstairs.attributes.current_temperature }}

value_template is the way to go yes.

Thank you!

Been plugging away all day at this… So, if I trigger on platform: template, using the template you provided, my automation will trigger anytime the current_temperature attribute changes, correct?

Again - huge thanks!!

Theoretically, yes. If you have an issue, then post your code here and we’ll try to work it out.

Sadly, no luck… Here’s the automation:

`alias: testingtemp
 trigger:
   platform: template
   value_template: "{{ states.climate.downstairs.attributes.current_temperature }}"
 action:
   service: script.turn_on
   data:
     entity_id: script.temptest
  `

… and the script referenced in the action:

 temptest:
   alias: TempTest
   sequence:
     - service: notify.my_droid
       data:
         message: 'T- {{ states.climate.downstairs.attributes.current_temperature}}'

The script runs when triggered manually, leading me to believe the automation is not triggering. No errors in home-assistant.log

You need to do some math in the value template to determine the temp threshold and trigger a “true” response; something like:

value_template: "{{ states.climate.downstairs.attributes.current_temperature > 27 }}"

Try that.

Also, you may have to use data_template: instead of data: in your notification to get the actual value to show up instead of the template’s text…

- service: notify.my_droid
    data_template:
      message: >
        T- {{ states.climate.downstairs.attributes.current_temperature}}

hmm… The notification does send the value when I trigger it manually. But, if it would be better practice in general, I’ll make this change, too.

Thanks again - this has been a huge help. I’m a reasonably technical person (you should see my tasker profiles on Android :wink: - but it’s taking me some time to get my head around yaml, with states, entities, domains, attributes, etc… Hopefully by the time I have more than 2 thermostats, a garage door and a couple of lights, I’ll have it figured out and can start getting the automation piece done…

1 Like

Yeah Yaml is hard. I’ve migrated all automations to the Appdaemon instead. It is easier to get Python to do what you want. Also ‘easier’ to do achieve more advanced behaviors

2 Likes

No value no trigger. You need to tell it when to trigger.
All you did right now is where to look for the value but not when to trigger.

I’ve looked at AppDaemon and think I might go that way.prerty sure I’ll have more luck with the learning curve. My trigger still isn’t working, but going back to work today, I’m going to have less time to work through it.

One question about AppDaemon - can you temporarily disable apps? Use case that comes to mind would be something like an “away” scene, where I wouldn’t want thermostat automations to run, for example. Suppose there’s a way to use a condition on a binary variable, if need be…

Anyways, thanks again. Really do appreciate the help. I’m really liking HA so far after just a couple of weeks. Once I get the automation of rules sorted one way or another, I’m excited to be in for this ride.

You can add constraints on parameters from HASS

# Single value
constrain_input_select = input_select.house_mode,Day
# or multiple values
constrain_input_select = input_select.house_mode,Day,Evening,Night

I use an input boolean for this - as a condition in the app. But you could also just comment out sections in appdaemon.cfg. appdaemon stops the app as soon as the config file has changed.

The latter would be challenging for me, in that I’d want to enable/disable apps in real time, but it does look like there are several possibilities. mostly by using constraints, that will solve what I’m thinking.

I’ve got a busy few days ahead, but am definitely looking forward to starting fresh with AppDaemon next week. Converting the 6 automations I have now will be a good exercise to learn the basics…

Best of luck to ya! :smile: