#Automation to turn on heat pump only inside specific hours and specific power consumption from grid

1 messages · Page 1 of 1 (latest)

sterile phoenix
#

Hi, i want to create an automation that uses a Heat pump that turns on only specified hours every day (when i'm not home) and only if below let's say -1500W going to the power grid and turn off if the hours are outside of the specified range or the power going outside the grid is higher than -500W. I have created this template, but not sure how to set it up correctly so i ask some help if someone knows how to configure a more sophisticated automation like this. ```yaml
mode: single
triggers:

  • value_template: >-
    {% set map = {1:'mon', 2:'tue', 3:'wed', 4:'thu', 5:'fri', 6:'sat',
    7:'sun'} %}

    {% set schedule =
    {'mon':'12:00','tue':'10:00','wed':'8:00','thu':'10:00','fri':'12:00'} %} %%%%turn ON time

    {% set dayofweek = map[now().isoweekday()] %}

    {{ false if dayofweek not in schedule.keys() else now() >
    today_at(schedule.get(dayofweek)) }}
    trigger: template
    {'mon':'17:00','tue':'16:30','wed':'19:00','thu':'16:00','fri':'14:00'} %} %%%%turn OFF time
    conditions:

  • condition: numeric_state
    entity_id: sensor.power
    below: -1500

  • condition: numeric_state
    entity_id: sensor.power
    above: -500

actions:

  • device_id: ******
    domain: climate
    entity_id: *****
    type: set_hvac_mode```
nocturne crown
#

So the way I have done something similar could be done with a schedule helper, a threshold helper, and a binary template sensor
Set up the times you want it to run in the schedule helper
Set up your power limits in the threshold helper - use set point of 1000 and hysteresis of 500 and it will turn on above 1500 and turn off below 500
Finally make a binary sensor template that just returns true if both the schedule and threshold sensor are on
Automation then it's just: binary sensor changes state: turn on/off as appropriate

sterile phoenix
#

Isn't there a one script automation alternative, so that i don't need to create unnecessary helpers in the process?

nocturne crown
#

You could.. but what's the problem with helpers? they make things easier

sterile phoenix
#

For me it's easier to track one automation if i let's say wanna lookup things after 5 years.

nocturne crown
#

You can assign all the helpers to your heat pump so they will all show up in the same page when looking for things related to heat pump

#

but sure - you basically need 4 triggers and 2 trigger ids

  1. template: end_time > now > start_time - id "turn_on"
  2. numeric_state: power < -1500 - id "turn_on"
  3. template: now > end_time - id "turn_off"
  4. numeric_state: power > -500 - id "turn_off"
#

then just a choose action based on the trigger id and turn off/on as appropriate

#

for turn on you will also need to check: end_time > now > start_time AND power < -1500, but turn off just whenever

sterile phoenix
#

The schedule helper is fine, but i would stick with the yaml config for the rest. I never used the schedule helper and i find it very intuitive.

nocturne crown
#

ok, then you want to change it to
1. state: schedule helper from off to on
3. state: schedule helper from on to off

sterile phoenix
#
triggers:
  - trigger: state
    entity_id:
      - schedule.timetable
    from: "off"
    to: "on"
  - trigger: numeric_state
    entity_id:
      - sensor.power
    below: -1500
  - trigger: numeric_state
    entity_id:
      - sensor.power
    above: -500
  - trigger: state
    entity_id:
      - schedule.timetable
    from: "on"
    to: "off"
conditions: []
actions:
  - device_id: *****
    domain: climate
    entity_id: *****
    type: set_hvac_mode
    hvac_mode: heat
mode: single
#

I hope it's good...

nocturne crown
#

give the 3rd and 4th triggers the id "turn off"

#

id: turn_off under each of them

#

then a choose action

sterile phoenix
#

Like this? ```yaml
triggers:

  • trigger: state
    entity_id:
    • schedule.timetable
      from: "off"
      to: "on"
  • trigger: numeric_state
    entity_id:
    • sensor.power
      below: -1500
  • trigger: numeric_state
    entity_id:
    • sensor.power
      above: -500
      id: turn_off
  • trigger: state
    entity_id:
    • schedule.timetable
      from: "on"
      to: "off"
      id: turn_off```
nocturne crown
#

block 1
Condition: trigger id = turn_off
Sequence: climate.turn_off

#

block 2
Condition:

  • state schedule.timetable = on
  • numeric state sensor.power below -1500
    sequence: climate.turn_on
sterile phoenix
#

where to put the numeric state? ```yaml
triggers:

  • trigger: state
    entity_id:
    • schedule.timetable
      from: "off"
      to: "on"
  • trigger: numeric_state
    entity_id:
    • sensor.power
      below: -1500
  • trigger: numeric_state
    entity_id:
    • sensor.power
      above: -500
      id: turn_off
  • trigger: state
    entity_id:
    • schedule.timetable
      from: "on"
      to: "off"
      id: turn_off
      conditions: []
      actions:
  • condition: trigger
    id:
    • turn_off
  • condition: state
    entity_id: schedule.timetable
    state: "on"
    mode: single```
#

Did i miss something? I'm new to automating things using HA, i'm more used to configuring things using ESPHome (the microcontroller way).

nocturne crown
#

You missed the Choose block

#

should look something like this under actions:

actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - turn_off
        sequence: []
      - conditions:
          - condition: numeric_state
            entity_id: ""
          - condition: state
            entity_id: ""
            state: ""
        sequence: []
sterile phoenix
#

I think this is the final version: ```yaml
alias: HeatPUMP
description: ""
triggers:

  • trigger: state
    entity_id:
    • schedule.timetable
      from: "off"
      to: "on"
  • trigger: numeric_state
    entity_id:
    • sensor.power
      below: -1500
  • trigger: numeric_state
    entity_id:
    • sensor.power
      above: -500
      id: turn_off
  • trigger: state
    entity_id:
    • schedule.timetable
      from: "on"
      to: "off"
      id: turn_off
      conditions: []
      actions:
  • choose:
    • conditions:
      • condition: trigger
        id:
        • turn_off
          sequence:
      • action: climate.set_hvac_mode
        metadata: {}
        data:
        hvac_mode: "off"
        target:
        entity_id: climate.heatpump
    • conditions:
      • condition: numeric_state
        entity_id: sensor.power
        below: -1500
      • condition: state
        entity_id: schedule.timetable
        state: "on"
        sequence:
      • action: climate.set_hvac_mode
        metadata: {}
        data:
        hvac_mode: heat
        target:
        entity_id: climate.heatpump
        mode: single
#

I just hope it won't turn on/off rapidly, a larger hysteresis might be needed, i will be testing it out in the coming days. (Or just using an average over ex: 15min on the power meter)

nocturne crown
#

you want to put the state schedule.timetable = on in the 2ndset of conditions too

#

otherwise it can turn on whenever the power is <-1500 and ignores the schedule you've set

sterile phoenix
#

Error: In 'numeric_state' condition: entity schedule.timetable state 'on' cannot be processed as a number

#

Tomorrow i will try it out with the modified code.

nocturne crown
#

It's the one above that

#

You are checking the timetable sensor not the power sensor

sterile phoenix
#

How to add a feature where if it will stay on even if the specified power (in this example: -500) is held for more? In this example i want to have a 10 minutes buffer time for when it considers to turn off the heat pump. (I need to reduce the number of time it turns off). I used a - delay: 300 but it did not satisfy my requirement. Should i increase it to 600 -> 10min for it to work or is there another method?

nocturne crown
#

add a "for" attribute to the sensor.power > -500 trigger, then it will only try to turn the system off if it has been true for that amount of time

sterile phoenix
#

and where to put the delay for it to work?

nocturne crown
#

no delay

sterile phoenix
#

Like this: ```yaml

  • trigger: numeric_state
    entity_id:
    • sensor.power
      above: -500
      id: turn_off
      for:
      hours: 0
      minutes: 10
      seconds: 0```
nocturne crown
#

yup

#

now that trigger will only turn off if it is above -500 for 10 minutes

#

so if it goes -490 for a minute and then back to -510, it will stay on

sterile phoenix
#

Thanks again for helping!