Help to set automation trigger for thermostat

Hello,
my goal is schedule an automation to manage my thermostat.
I need do this:
from 5.30 to 21.30 if temp is below 21°C start sonoff…very easy No?

The problem is this:
To do the automation i need to use numeric_state, but the numeric state work only when the value change, example to explain better:
Now at home my sensor is to 21°C, I build this automation (use notified instead switch because is easier to verify):
- alias: ‘termostato on’
hide_entity: true
trigger:
- platform: numeric_state
entity_id: my_sensor
above: 19
action:
- service: notify.telegram
data:
message: calderina accesa

When reload the automation all is mute…no notification, but if i wait the change of value (the temperature) of the sensor, example 19.1 or 18.9, the notification arrived. This is because the numeric_state is passive.
This is unusable for thermostat…i need to read the temp value in real time not when state change.
Any idea?
thanks in advance

Maybe you should try using the Generic Thermostat instead of creating automations. I haven’t used it, but it sounds like it is exactly what you’re looking for.

Thank you for reply, the problem of generic thermostat is that it cant be schuduled

In this case you may simply use a time trigger. If you are on the latest HA 0.86 then try this:

- alias: 'Thermostat'
  hide_entity: True
  trigger:
    platform: time_pattern
    minutes: '/1' 
  action:
  - service: notify.telegram
    data:
      message: calderina accesa
  condition:
    condition: and
    conditions:
      - condition: numeric_state
        entity_id: my_sensor
        above: '19'
      - condition: time
        after: '05:30:00'
        before: '21:00:00'

This will check every minutes if the both conditions are true. And will then send the notification.

What exactly do you mean by “scheduled”? E.g., do you mean only allow the switch (i.e., heater) to be turned on during a certain period (5:30 - 21:30)? Do you mean change the target temperature at different times? Or something else?

BTW, you’ve only described turning the switch on, but I would assume you also want it to turn off when the temperature rises above the target temperature. Is that right? And (depending on the answers to the questions above) maybe turn it off outside the specified time period, yes?

If I understand your setup correctly you have a sensor that indicates the current temperature, and a switch that turns the heater on and off. Is that right?

Assuming I understand what you want to do, then the Generic Thermostat should still work. When “turned on” (or set to heat mode) it will automatically control the heater (via the switch entity) based on the temperature indicated by the sensor. When “turned off” it will simply turn the switch (i.e., heater) off. Then all you need to “schedule” it are automations that turn it on and off. Something like:

- alias: Thermostat on
  trigger:
    platform: time
    at: 05:30:00
  action:
    service: climate.turn_on
    entity_id: climate.my_thermostat
- alias: Thermostat off
  trigger:
    platform: time
    at: 21:30:00
  action:
    service: climate.turn_off
    entity_id: climate.my_thermostat

This has the added benefit of having typical “thermostat” features such as minimal cycle times, hysteresis, away mode, etc. that should protect your heater and give you more operational capabilities, and also a climate entity in the front end that gives you manual control, etc., etc.

But if you really would rather create your own automations to directly control the heater, then what you need are some additional triggers and conditions, something like:

- alias: termostato on
  hide_entity: true
  trigger:
    - platform: numeric_state
      entity_id: sensor.my_sensor
      above: 19
    - platform: time
      at: 05:30:00
    - platform: homeassistant
      event: start
  condition:
    - condition: numeric_state
      entity_id: sensor.my_sensor
      above: 19
    - platform: time
      after: 05:30:00
      before: 21:30:00
  action:
    ...
1 Like

This solution is more close wiht the idea of thermostat only if i can setup 2 different times for 2 different temperaturea. My goal is from 5.30 to 21 temp between 21 and 21.3°, from 21.00 to 5.30 between 17 and 18°. With trigger i need to switch6on/off a sensor

Ok, so you don’t want to turn the thermostat on and off at different times, you want to change the target temperature at different times. So that would look like this:

- alias: Raise thermostat target temperature
  trigger:
    - platform: time
      at: '05:30:00'
    - platform: homeassistant
      event: start
  condition:
    condition: time
    after: '05:30:00'
    before: '21:00:00'
  action:
    service: climate.set_temperature
    entity_id: climate.my_thermostat
    data:
      temperature: 21
- alias: Lower thermostat target temperature
  trigger:
    - platform: time
      at: '21:00:00'
    - platform: homeassistant
      event: start
  condition:
    condition: time
    after: '21:00:00'
    before: '05:30:00'
  action:
    service: climate.set_temperature
    entity_id: climate.my_thermostat
    data:
      temperature: 17
1 Like

Good! This works with generic thermostat? Where i need to indicate my sensor and switch?
Thanks for your help

Yes, the above automations assume you have created a generic thermostat (whose entity_id is climate.my_thermostat. If you give it another name, then adjust accordingly.)

See the generic thermostat doc page I provided a link to above for how to set it up. If you run into trouble getting that working, let me know.

Thank you very much,!! Il read tomorrow morning

I’ve had a fast read about generic thermostat, when create it i don’t need to set target temperature because its set into automation right?

Yes, I think that should be ok, since one of the automations will run at startup and set the target temperature.

Hello,
i’ve added the generic thermostat at my configuration.yaml and i’ts ok, when add the automation the confuguration is not validate, this is the errror:

Invalid config for [automation]: extra keys not allowed @ data[‘condition’][0][‘after’]. Got None extra keys not allowed @ data[‘condition’][0][‘before’]. Got None not a valid value for dictionary value @ data[‘condition’][0][‘condition’]. Got None required key not provided @ data[‘condition’][0][‘entity_id’]. Got None. (See /config/configuration.yaml, line 89). Please check the docs at https://home-assistant.io/components/automation/ Invalid config for [automation]: Invalid time specified: 75600 for dictionary value @ data[‘trigger’][0][‘at’]. Got None extra keys not allowed @ data[‘condition’][0][‘after’]. Got None extra keys not allowed @ data[‘condition’][0][‘before’]. Got None not a valid value for dictionary value @ data[‘condition’][0][‘condition’]. Got None required key not provided @ data[‘condition’][0][‘entity_id’]. Got None. (See /config/configuration.yaml, line 89). Please check the docs at https://home-assistant.io/components/automation/

Automation is this.

- alias: Riscaldamento giorno
  trigger:
    - platform: time
      at: 05:30:00
    - platform: homeassistant
      event: start
  condition:
    condition: time
    after: 05:30:00
    before: 21:00:00
  action:
    service: climate.set_temperature
    entity_id: sensor.temperature_158d0002b549f4
    data:
      temperature: 21
- alias: Riscaldamento notte
  trigger:
    - platform: time
      at: 21:00:00
    - platform: homeassistant
      event: start
  condition:
    condition: time
    after: 21:00:00
    before: 05:30:00
  action:
    service: climate.set_temperature
    entity_id: sensor.temperature_158d0002b549f4
    data:
     temperature: 17

I’vv wrote the time for trigger and condition with single quote and now the configuration is validate. Thank you veru much sir!!!

Now i’ll try and let you know if it’s ok

1 Like

Ok, I’ll go back and edit my suggestion in case anyone comes across this in the future.

Ok.
Last info, in the action the thermostat is my switch that star the boiler right?

When you added the generic thermostat to your configuration, it should have created an entity with an entity_id that starts with “climate.” and ends with the name you entered for it (in all lower case letters.) Look on the States page for it.

EDIT: That’s what you should use for the entity_id fields in the actions, not sensor.temperature_158d0002b549f4.

Ah ok.its clear now. Thank you

1 Like

Ok…last recap.
This is my conf

climate:
  - platform: generic_thermostat
    name: Termostato
    heater: switch.termostato
    target_sensor: sensor.temperature_158d0002b549f4
    min_temp: 15
    max_temp: 23
    ac_mode: false
    #target_temp: 17
    cold_tolerance: 0.2
    #hot_tolerance: 0
    min_cycle_duration:
      seconds: 5
    #keep_alive:
    #  minutes: 3
    initial_operation_mode: "off"
    #away_temp: 16
    #precision: 0.1`Preformatted text`

where heater is my switch (sonoff in my case) and target sensor si my temp sensor.
I’ve commented target temperature because, i suppose, itìs recall from automation…and rest i hope it’s correct

This is the automation:

- alias: Riscaldamento giorno
  trigger:
    - platform: time
      at: '05:30:00'
    - platform: homeassistant
      event: start
  condition:
    condition: time
    after: '05:30:00'
    before: '21:00:00'
  action:
    service: climate.set_temperature
    entity_id: climate.termostato
    data:
      temperature: 23
- alias: Riscaldamento notte
  trigger:
    - platform: time
      at: '21:00:00'
    - platform: homeassistant
      event: start
  condition:
    condition: time
    after: '21:00:00'
    before: '05:30:00'
  action:
    service: climate.set_temperature
    entity_id: climate.termostato
    data:
     temperature: 21

Where entity id is the entity discovered in entity list with the name “climate.termostato” (as suggested by you)

it’s all ok?

Looks good to me! Hope it works!! :slight_smile: