YAHWT - Heating week timer

As an exercise, I streamlined the template for sensor.heating_program (it passes config check).

  - platform: template
    sensors:
      heating_program:
        friendly_name: "Heating Program"
        value_template: >-  # ok 141119
          {% set t = states('sensor.time') %}
          {% if is_state('binary_sensor.workday_today', 'on') %}
            {% if now().weekday() in (0,1,2,3,4) %}
              {%   if states('input_datetime.p1_weekday_on') <= t <= states('input_datetime.p2_weekday_on') %} p1_weekday
              {% elif states('input_datetime.p2_weekday_on') <= t <= states('input_datetime.p3_weekday_on') %} p2_weekday
              {% elif states('input_datetime.p3_weekday_on') <= t <= states('input_datetime.p4_weekday_on') %} p3_weekday 
              {% elif states('input_datetime.p4_weekday_on') <= t <= states('input_datetime.p5_weekday_on') %} p4_weekday
              {% elif states('input_datetime.p5_weekday_on') <= t <= states('input_datetime.p6_weekday_on') %} p5_weekday
              {% elif states('input_datetime.p6_weekday_on') <= t < '23:59' %} p6_weekday
              {% elif '00:00' <= t <= states('input_datetime.p1_weekday_on') %} p0_weekday
              {% else %} error
              {% endif %}
            {% else %}
              {%   if states('input_datetime.p1_saturday_on') <= t <= states('input_datetime.p2_saturday_on') %} p1_saturday
              {% elif states('input_datetime.p2_saturday_on') <= t <= states('input_datetime.p3_saturday_on') %} p2_saturday
              {% elif states('input_datetime.p3_saturday_on') <= t <= states('input_datetime.p4_saturday_on') %} p3_saturday 
              {% elif states('input_datetime.p4_saturday_on') <= t <= states('input_datetime.p5_saturday_on') %} p4_saturday
              {% elif states('input_datetime.p5_saturday_on') <= t <= states('input_datetime.p6_saturday_on') %} p5_saturday
              {% elif states('input_datetime.p6_saturday_on') <= t <= '23:59' %} p6_saturday
              {% elif '00:00' <= t <= states('input_datetime.p1_saturday_on') %} p0_saturday
              {% else %} error
              {% endif %}
            {% endif %}
          {% else %}
            {%   if states('input_datetime.p1_holiday_on') <= t <= states('input_datetime.p2_holiday_on') %} p1_holiday
            {% elif states('input_datetime.p2_holiday_on') <= t <= states('input_datetime.p3_holiday_on') %} p2_holiday
            {% elif states('input_datetime.p3_holiday_on') <= t <= states('input_datetime.p4_holiday_on') %} p3_holiday 
            {% elif states('input_datetime.p4_holiday_on') <= t <= states('input_datetime.p5_holiday_on') %} p4_holiday
            {% elif states('input_datetime.p5_holiday_on') <= t <= states('input_datetime.p6_holiday_on') %} p5_holiday
            {% elif states('input_datetime.p6_holiday_on') <= t <= '23:59' %} p6_holiday
            {% elif '00:00' <= t <= states('input_datetime.p1_holiday_on') %} p0_holiday
            {% else %} error
            {% endif %}
          {% endif %}
1 Like

I did something similar some time ago, but tried to make UI a bit more wife friendly:

Nice work!

FYI:
You can reduce the value_template from this

"{{ states('sensor.time') == state_attr('input_datetime.weekdays_am_hot_water_on', 'timestamp') | int | timestamp_custom('%H:%M', false) }}"

to this

"{{ states('sensor.time') == states('input_datetime.weekdays_am_hot_water_on')[:5] }}"

2 Likes

Looks like it would be a great frontend to control something like schedy (the app formerly known as heaty)

1 Like

Funny thing is that I’m using substrings everywhere in my config but somehow I blindly copied someone’s code for comparing data without even thinking about it :slight_smile:

This is a great Project @gt4020, I’ve borrowed a considerable portion of your code to get my own project up and running, but I’m slowly evolving it to suit my own heating system.

https://community.home-assistant.io/t/multi-zone-heating-with-scheduling/160280

1 Like

Can someone convert the automation part from configuration.yaml to the new format for automation.yaml file?
Thank you.

There is no difference.

Hi Giovanni
thank you for your project, i implemented your thermostat on raspberry and it always worked fine. But since I upgraded HA to core-2021.2.3 it doesn't work anymore. It is no longer able to switch to the temperatures set by the interface on schedule hvac_temperature_knob always remains at the temperature set in the generic_thermostat. I double-checked the config files and they are correct. I think the problem is in the automations that don't trigger. I noticed that if I activate the work_timer automation, the temperature setting on the thermostat fine. In other cases, no. Thank you if you can help me solve this problem also because the project is very valid and I repeat, it has worked very well until now Thanks Mario

Are you sure? I’m on version core-2021.3.1 and it works. Did you mean core-2021.3.2?

yes core-2021.2.3

Versione core-2021.2.3
Tipo di installazione Home Assistant Core
Sviluppo false
Supervisore false
Docker false
Ambiente virtuale true
Versione Python 3.8.6
Famiglia del Sistema Operativo Linux
Versione del Sistema Operativo 5.10.11+
Architettura della CPU armv6l
Fuso orario Europe/Rome

Logs?

Your automation?

I’ve managed to migrate this config from configuration.yaml to automations.yaml but I have problems with the timers for the Heating Timer and for the Heating lock Timer. The switch is doing it’s job but the timer does not work, when turned on it should turn back off after the specified time, but it doesn’t do that.
My automation.yaml looks like this:

alias: Heating_lock_Timer
trigger:

  • platform: state
    entity_id: input_boolean.switch_heating_lock_timer
    to: ‘off’
  • platform: state
    entity_id: input_boolean.switch_heating_lock_timer
    to: ‘on’
    for: ‘minutes: ‘’{{ states.input_number.heating_lock_timer.state | int }}’’’
    action:
  • service: input_boolean.turn_off
    target:
    entity_id:
    • input_boolean.switch_heating_lock_timer
  • service: climate.set_hvac_mode
    target:
    entity_id: climate.ha_thermo
    data:
    hvac_mode: heat

alias: caldaia temporizzata off
description: ‘’
trigger:

  • platform: state
    entity_id: input_boolean.switch_caldaia_timer
    for: ‘off’
  • platform: state
    entity_id: input_boolean.switch_caldaia_timer
    to: ‘on’
    for: ‘minutes: ‘’{{ states.input_number.caldaia_timer.state | int }}’’’
    condition: []
    action:
  • service: input_boolean.turn_off
    target:
    entity_id:
    • input_boolean.switch_caldaia_timer
  • service: climate.set_temperature
    target:
    entity_id: climate.ha_thermo
    data:
    temperature: ‘{{ states.input_number.t0_temp.state }}’
    mode: single

I suspect the synthax for minutes is wrong even the config check does not return any error.

Change it to this:

    for:
      minutes: '{{ states.input_number.caldaia_timer.state | int }}'

That’s the way the documentation shows how to do it in the fifth example in Holding a state.


EDIT

I overlooked to mention that the preferred way of getting an entity’s state value is by using the states() function (refer to the Warning message here).

    for:
      minutes: "{{ states('input_number.caldaia_timer') | int }}"

I’ve tried both examples, I receive the following error message:
Invalid config for [automation]: [minutes] is an invalid option for [automation]. Check: automation->minutes. (See /config/configuration.yaml, line 8).

Then you’re doing something wrong but I don’t know what it is until you post the modified automation.

Yes, you were right I’ve missplaced it, instead of placing the line into the “caldaia temporizzata off” automation, I’ve placed it into the “Heating_lock_Timer” automation. Now I’ve placed it into the right spot and it’s working perfectly. Using the synthax provided by you, I’ve managed to solve the synthax for “Heating_lock_Timer” automation. Both automation are now working.
Thank you very much for helping me.

Ciao Giovanni,
bel progetto! funziona benissimo! Cosa dovrei fare, se è possibile, per comandare 2 zone distinte? es. zona giorno e zona notte. vorrei comandare le due temperature autonomamente.

Hi Giovanni,
nice project! it works great! What should I do, if possible, to control 2 distinct zones? ex. living area and sleeping area. I would like to control the two temperatures independently.

I’ve been using this thermostat many years, but after upgrading HA to 2023.7.0 the weekely program is no longer working, I have the 2 following errors:
Error while executing automation automation.temp_lock: expected float for dictionary value @ data[‘temperature’]
temp_lock: Error executing script. Invalid data for call_service at pos 1: expected float for dictionary value @ data[‘temperature’]

The temp_lock automation looks like this:
alias: temp_lock
description: “”
trigger:

  • platform: state
    entity_id: sensor.hvac_temperature_knob
  • platform: state
    entity_id: input_boolean.heating_master
    to: “on”
    condition:
  • condition: state
    entity_id: input_boolean.switch_caldaia_timer
    state: “off”
  • condition: state
    entity_id: input_boolean.heating_master
    state: “on”
    action:
  • service: climate.set_temperature
    target:
    entity_id: climate.ha_thermo
    data_template:
    temperature: >-
    {% if is_state(‘sensor.heating_program’, ‘p1_weekday’) %} {{
    states.input_number.t1_work.state|float}} {% elif
    is_state(‘sensor.heating_program’, ‘p2_weekday’) %} {{
    states.input_number.t2_work.state }} {% elif
    is_state(‘sensor.heating_program’, ‘p3_weekday’) %} {{
    states.input_number.t3_work.state }} {% elif
    is_state(‘sensor.heating_program’, ‘p4_weekday’) %} {{
    states.input_number.t4_work.state }} {% elif
    is_state(‘sensor.heating_program’, ‘p5_weekday’) %} {{
    states.input_number.t5_work.state }} {% elif
    is_state(‘sensor.heating_program’, ‘p0_weekday’) %} {{
    states.input_number.t0_temp.state }} {% elif
    is_state(‘sensor.heating_program’, ‘p1_saturday’) %} {{
    states.input_number.t1_sat.state }} {% elif
    is_state(‘sensor.heating_program’, ‘p2_saturday’) %} {{
    states.input_number.t2_sat.state }} {% elif
    is_state(‘sensor.heating_program’, ‘p3_saturday’) %} {{
    states.input_number.t3_sat.state }} {% elif
    is_state(‘sensor.heating_program’, ‘p4_saturday’) %} {{
    states.input_number.t4_sat.state }} {% elif
    is_state(‘sensor.heating_program’, ‘p5_saturday’) %} {{
    states.input_number.t5_sat.state }} {% elif
    is_state(‘sensor.heating_program’, ‘p0_saturday’) %} {{
    states.input_number.t0_temp.state }} {% elif
    is_state(‘sensor.heating_program’, ‘p1_holiday’) %} {{
    states.input_number.t1_sun.state }} {% elif
    is_state(‘sensor.heating_program’, ‘p2_holiday’) %} {{
    states.input_number.t2_sun.state }} {% elif
    is_state(‘sensor.heating_program’, ‘p3_holiday’) %} {{
    states.input_number.t3_sun.state }} {% elif
    is_state(‘sensor.heating_program’, ‘p4_holiday’) %} {{
    states.input_number.t4_sun.state }} {% elif
    is_state(‘sensor.heating_program’, ‘p5_holiday’) %} {{
    states.input_number.t5_sun.state }} {% elif
    is_state(‘sensor.heating_program’, ‘p0_holiday’) %} {{
    states.input_number.t0_temp.state }} {% endif %}
    mode: single

What could be the problem?

The problem came from the workday binary sensor in configuration.yaml
binary_sensor:

  • platform: workday
    country: ‘IT’
    name: ‘workday_today’
    workdays: [mon, tue, wed, thu, fri, sat]
    excludes: [sun, holiday]

Now the sensor is an integration and after installation you have to add a workday_today device.