jagheterfredrik / esphome-rego1000

ESPHome custom component for IVT Rego1000 heat pump controller
12 stars 5 forks source link

Request - Possible to make "Holiday mode" work? #12

Closed stomko11 closed 1 year ago

stomko11 commented 1 year ago

As title says, would it be possible to enable Holiday mode selector? On heatpump, when activated, it allows to set date until when this is active. So either this way, or possibly just enable/disable as I could then turn it off via HA (if heatpump lets enabling it without date set)

jagheterfredrik commented 1 year ago

Not sure I follow what you want but you should be able to add a switch for $HOLIDAY_ACTIVE to turn on/off. You could also set dates using a number for the holiday start/stop variables. Does that help?

stomko11 commented 1 year ago

I was thinking about it. There are duplicate values, one with _GLOBAL. Any idea what they might be for?

IMG_20230618_114228

jagheterfredrik commented 1 year ago

I’m actually not sure but I think I went for the non-global ones in other places

edit: my hypothesis is that it has to do with pumps with multiple heating circuits, global then controlling all at the same time but as our pump only have one 🤷‍♂️

stomko11 commented 1 year ago

Thank you. Works perfectly. I mad few things around it so that it is easier (for me) to set it. By default, when you activate holiday mode, it would set start and end date to be tomorrow and +7 days from tomorrow. So this is what I came up with:

Defined numbers for day/month/year for start and end:

- platform: rego1000
  name: Holiday Start Day
  rego_variable: $HOLIDAY_START_DAY
  min_value: 1
  max_value: 31
  step: 1
  mode: box
- platform: rego1000
  name: Holiday Start Month
  rego_variable: $HOLIDAY_START_MONTH
  min_value: 1
  max_value: 12
  step: 1
  mode: box
- platform: rego1000
  name: Holiday Start Year
  rego_variable: $HOLIDAY_START_YEAR
  min_value: 23
  max_value: 49
  step: 1
  mode: box
- platform: rego1000
  name: Holiday Stop Day
  rego_variable: $HOLIDAY_STOP_DAY
  min_value: 1
  max_value: 31
  step: 1
  mode: box
- platform: rego1000
  name: Holiday Stop Month
  rego_variable: $HOLIDAY_STOP_MONTH
  min_value: 1
  max_value: 12
  step: 1
  mode: box
- platform: rego1000
  name: Holiday Stop Year
  rego_variable: $HOLIDAY_STOP_YEAR
  min_value: 23
  max_value: 49
  step: 1
  mode: box

I did define mode box, but it is anyway not very user friendly. More later. I also defined switches for holiday mode on/off and blocking of DHW while in holiday mode:

- platform: rego1000
  name: "Holiday Mode"
  rego_variable: $HOLIDAY_ACTIVE
- platform: rego1000
  name: "Block DHW in Holiday Mode"
  rego_variable: $HOLIDAY_DHW

Now within HA, I wanted a nicer way to select dates, not inputting numbers manually (what if I would select nonexistent date, etc.). So I created datetime objects (holding just date) for start and end that allows me to easily select dates from calendar. When I select start date, end date automaticaly is +14 days from start. Pressing the button actually sets those dates to heatpump. Also, thanks to few custom cards, secondary info below name shows what's currently set. This is how it looks like:

image

This is the yaml for card:

type: entities
entities:
  - entity: switch.ivt_holiday_mode
    name: Holiday Mode
  - entity: switch.ivt_block_dhw_in_holiday_mode
    name: Block DHW in Holiday Mode
  - entity: input_datetime.ivt_vacation_start
    name: Start
    type: custom:secondaryinfo-entity-row
    secondary_info: >-
      Set {{ states('number.ivt_holiday_start_day')|int}}.{{
      states('number.ivt_holiday_start_month')|int}}.20{{
      states('number.ivt_holiday_start_year')|int}}
  - entity: input_datetime.ivt_vacation_end
    name: End
    type: custom:secondaryinfo-entity-row
    secondary_info: >-
      Set {{ states('number.ivt_holiday_stop_day')|int}}.{{
      states('number.ivt_holiday_stop_month')|int}}.20{{
      states('number.ivt_holiday_stop_year')|int}}
  - entity: input_button.ivt_vacation_set
    name: Set Holiday Mode Dates
title: IVT Holiday Mode
show_header_toggle: false

And automation takes care of setting dates (+14 days) and actually setting the dates to heatpump:

alias: IVT
description: ""
trigger:
  - platform: state
    entity_id:
      - input_datetime.ivt_vacation_start
    id: ivt-vacation-start-changed
  - platform: state
    entity_id:
      - input_button.ivt_vacation_set
    to: null
    id: ivt-vacation-button-pressed
condition: []
action:
  - if:
      - condition: trigger
        id: ivt-vacation-start-changed
    then:
      - service: input_datetime.set_datetime
        data:
          date: >-
            {{((states('input_datetime.ivt_vacation_start')|as_datetime) +
            timedelta(days=14)).strftime('%Y-%m-%d')}}
        target:
          entity_id: input_datetime.ivt_vacation_end
  - if:
      - condition: trigger
        id: ivt-vacation-button-pressed
    then:
      - service: number.set_value
        data:
          value: "{{state_attr('input_datetime.ivt_vacation_start', 'day') }}"
        target:
          entity_id: number.ivt_holiday_start_day
      - service: number.set_value
        data:
          value: "{{state_attr('input_datetime.ivt_vacation_start', 'month') }}"
        target:
          entity_id: number.ivt_holiday_start_month
      - service: number.set_value
        data:
          value: "{{states('sensor.ivt_year_start_template') | int }}"
        target:
          entity_id: number.ivt_holiday_start_year
      - service: number.set_value
        data:
          value: "{{state_attr('input_datetime.ivt_vacation_end', 'day') }}"
        target:
          entity_id: number.ivt_holiday_stop_day
      - service: number.set_value
        data:
          value: "{{state_attr('input_datetime.ivt_vacation_end', 'month') }}"
        target:
          entity_id: number.ivt_holiday_stop_month
      - service: number.set_value
        data:
          value: "{{states('sensor.ivt_year_stop_template') | int }}"
        target:
          entity_id: number.ivt_holiday_stop_year
mode: single

I am not very skilled user, but I wasn't able to find a way how to set year, as in datetime object, its attribute is "2023". When setting number, I used regex to strip first 2 digits as acceptable range is only 23-49 (and not 2023), but seems like it cannot be done - this was always omitted. So instead, I defined 2 template sensors first that do that and I am using those sensors in automation to set years. Here is definition of those 2 template sensors:

sensor:
  - platform: template
    sensors:
      ivt_year_start_template:
        friendly_name: "ivt Year Start Template"
        value_template: >-
          {{state_attr('input_datetime.ivt_vacation_start', 'year') | regex_findall_index('\d{2}$') | int }}

      ivt_year_end_template:
        friendly_name: "ivt Year End Template"
        value_template: >-
          {{state_attr('input_datetime.ivt_vacation_end', 'year') | regex_findall_index('\d{2}$') | int }}
jagheterfredrik commented 1 year ago

Thanks for the detailed instructions and glad you got it working!