Generic thermostat: need help with automation to override schedule

Hi to all,
I need a help with an automation.

I have a generic thermostat and this two automations:

- id: CALDAIA_ON_20200625121500
  alias: TERMOSIFONI - Accensione
  trigger:
  - minutes: /1
    platform: time_pattern
  condition:
  - after: '17:00:00'
    before: '22:00:00'
    condition: time
  - condition: and
    conditions:
    - condition: state
      entity_id: climate.caldaia
      state: "off"
  action:
  - entity_id: climate.caldaia
    service: climate.turn_on
- id: CALDAIA_OFF_20200625121600
  alias: TERMOSIFONI - Spegnimento
  trigger:
  - minutes: /1
    platform: time_pattern
  condition:
  - after: '23:00:00'
    before: '17:00:00'
    condition: time
  - condition: and
    conditions:
    - condition: state
      entity_id: climate.caldaia
      state: heat
  action:
  - entity_id: climate.caldaia
    service: climate.turn_off

Basically, my thermostat check the heater between 17 and 22, on other hours heater need to be off.

It seems works as expected.

Someday, I’m at home and I want to start the thermostat/heater out of the interval. For example, I want to have thermostat working at 13.00, so I would that thermostat goes on at 12.00 and when will be the 17.00 this “boost” (let’s call boost) is forgot.

Is it possible?

I thought on a virtual button called “start before” and another couple of automation… in pseudocode

if start_before is on than climate set on
and
if start_before is on and hour is 17.00, shut down start_before

Is there another way?

Thank you in advance and sorry for my english

I have an idea but first I have to ask a question:

When the heater should be on (between 17:00 and 23:00) and someone turns it off, your automation will turn the heater back on within a minute. Similarly when the heater should be off and someone turns it on, the automation turns it off within a minute. Is this “enforcement” of the heater’s state one of your design requirements?

Hey,
I’d like, but I tried and between 17-23 if I turn the heater off (it is a shelly switch) the heater remain off.
So, it would be an enforcenment but not strictly required…

(This is a screen of the heater (“caldaia” in italiano is off) and the thermostat. Heater (caldaia) was manually shut down via the input). Also after several minutes of waiting, it doesn’t go to “on”.

Update: the heater will go “on” when there is an update, e.g. the temperature sensor change its value.

I offer you a completely different way to achieve your goal. Be advised that I have not tested it so we may need to make a few adjustments before it works perfectly.

It consists of:

  • input_boolean to control when you want the ‘special schedule’
  • binary_sensor to serve as the heating schedule
  • automation to turn on/off climate.caldaia
  • optional automation to enforce the heating schedule

Unless you have already created sensor.time you will need to configure it:

sensor:
  - platform: time_date
    display_options:
      - 'time'

Create an input_boolean to control when your "Special Schedule’ (12:00 to 17:00) is enabled/disabled.

input_boolean:
  special_schedule:
    name: 'Special Schedule'

Create a Template Binary Sensor that serves as a schedule to indicate when to turn on, and enable heating, or to turn off. The regular heating schedule is between 17:00 and 23:00.

binary_sensor:
  - platform: template
    sensors:
      heater_schedule:
        friendly_name: 'Heater Schedule'
        entity_id: sensor.time, input_boolean.special_schedule
        value_template: >
          {% if is_state('input_boolean.special_schedule', 'on') %}
            {{ 12 <= now().hour < 17 }}
          {% else %}
            {{ 17 <= now().hour <= 23 }}
          {% endif %}

Create an automation to control the heater.

automation:
  - alias: 'Heater Schedule'
    trigger:
      platform: state
      entity_id: binary_sensor.heater_schedule
    action:
      service_template: 'climate.turn_{{trigger.to_state.state}}'
      entity_id: climate.caldaia

That’s all that’s needed to control the heater’s operation according to a schedule. To enable the Special Schedule, just turn on input_boolean.special_schedule and it will override the standard heating schedule.

The following additional automation is to enforce the heating schedule.

  • If someone sets climate.caldaia to off during the heating phase of its schedule, the automation will immediately turn it back on.
  • If someone sets climate.caldaia to heat during the non-heating phase of its schedule, the automation will immediately turn it back to off.
  - alias: 'Heater Schedule Enforcement'
    trigger:
      platform: state
      entity_id: climate.caldaia
    condition:
      condition: or
      conditions:
        - condition: template
          value_template: >
            {{ is_state('climate.caldaia', 'heat') and is_state('binary_sensor.heating_schedule', 'off') }}
        - condition: template
          value_template: >
            {{ is_state('climate.caldaia', 'off') and is_state('binary_sensor.heating_schedule', 'on') }}
    action:
      service_template: "climate.turn_{{ states('binary_sensor.heating_schedule') }}"
      entity_id: climate.caldaia

Oh, thank you for your time… The 12.00 was an example. My fault and forgive me for to be not-so clear that it was an example.

By the way, with your example I can imagine that my needs need to be done only with custom inputs. No automation “pre-default”.

Surely I will be inspired by you, thank you for the moment :slight_smile:

Yes, if you want to make it more sophisticated, where the hours can be set by the user (with an input_number or input_datetime), then you will need to replace these two templates in binary_sensor.heater_schedule

            {{ 12 <= now().hour < 17 }}

            {{ 17 <= now().hour <= 23 }}

With a bit of “and” and “or”, probably I got my result:

- id: CALDAIA_ON_20200625121500
  alias: TERMOSIFONI - Accensione
  trigger:
  - minutes: /1
    platform: time_pattern
  condition:
    condition: or
    conditions:
      - condition: time
        after: '10:00:00'
        before: '12:00:00'
      - condition: state
        entity_id: input_boolean.poweron_bypass_riscaldamento
        state: "on"
  action:
  - entity_id: climate.caldaia
    service: climate.turn_on
- id: CALDAIA_OFF_20200625121600
  alias: TERMOSIFONI - Spegnimento
  trigger:
  - minutes: /1
    platform: time_pattern
  condition:
    condition: and
    conditions:
      - condition: time
        after: '12:00:00'
        before: '10:00:00'
      - condition: or
        conditions:
          - condition: state
            entity_id: climate.caldaia
            state: heat
          - condition: state
            entity_id: switch.shelly01
            state: 'on'
      - condition: state
        entity_id: input_boolean.poweron_bypass_riscaldamento
        state: "off"
  action:
  - entity_id: climate.caldaia
    service: climate.turn_off

Heater goes on OR between time (10-12) OR if an input boolean is ON.
Heater doesn’t go off outside interval IF input_boolean is ON.

Unfortunately I need a third automation to set input_boolean to OFF in main time (10-12). I.e. in that time I don’t need at all.

I hoped to use only 2 automations, but it is not possible I think…