How to turn on heating for set time

I have noticed whilst it has been cold and fuel prices are high that I have been turning on my heating for short sharp bursts. I have a nest to do this - but I find I tend to want it on when I am cold not just because the schedule says I should. Ideally I just want buttons on my dashboard that just say heating on for X where X could be 5, 10, 15 minutes then turn off. Obviously it would not need to turn on if any of my temperature sensors are above a set level. Additionally, though it might have to be separate it would be good if I could still keep something about the temperature dropping to below Y temperature - but I can always stick these in different automations or use the safety temperature in nest.

How would I go about setting the heating, any thoughts greatly appreciated?

In terms of basic logic I assume it would be something like:

If button_toggle on then 
    start_time = now
    end_time = start_time + button_toggle_time

    foreach sensor in sensors
        if min_temp > sensor.temp then
            min_temp = sensor.temp
        if max_temp < sensor.temp then
            max_temp = sensor.temp

    avg_temp = avg(sensors.temp)

    loop while (time <= end_time) AND (start_time IS BETWEEN 1700 and 2030)
        if (avg_temp <= 18 OR min_temp <= 10) AND (nest.temp <= 20 OR max_temp <= 22) then
            turn heating on
        else
            turn heating off
        wait 30 seconds

button_toggle off

And my guess at HA yaml

push_for_heat_5:
alias: Push_To_Heat_For_5_Minutes
  trigger:
  - entity: push_for_heat_5_button
  action:
      sequence:
      - repeat:
          while: "{{ now().time < 2030 AND now().time > 1700 }}"
          sequence:
          - service: nest.turn_on
          - delay: '00:00:00'
          - service: nest.turn_off
          - delay: '00:00:00'
    default:
    - service: nest.turn_off

Instead of using a repeat, have your button add 5 minutes to a timer. Then have the timer’s events trigger turning the heat on/off. The following is a basic outline:

trigger:
  - platform: state
    id: button
    entity_id: input_button.boost_heat_timer
    variables:
      add_five: >
       {% set remaining = (state_attr('timer.boost_heat_timer', 'finishes_at')
       | default(0, 1) | as_datetime - now()).total_seconds() %}
       {{ iif( remaining > 0, remaining|int + 300, 300) }}
  - platform: event
    event_type:
      - timer.cancelled
      - timer.finished
    event_data:
      entity_id: timer.boost_heat_timer
  - platform: event
    id: timer_start
    event_type:
      - timer.start
    event_data:
      entity_id: timer.boost_heat_timer
condition:
action:
  - choose:
      - conditions:
          - condition: trigger
            id: button
        sequence:
          - service: timer.start
            data:
              duration: "{{ add_five }}"
            target:
              - entity_id: timer.boost_heat_timer
      - conditions:
          - condition: trigger
            id: timer_start
        sequence:
          - service: nest.turn_on
    default:
      - service: nest.turn_off
mode: queued

Depending on how your other heating automation(s) are set up, you could add a condition in them so the schedule doesn’t affect the Nest if the timer is active.

1 Like