Variable start time for generic thermostat controlled through automation

so we have an office and heating is controlled by generic thermostat.

right now I switch it from away temp to boost temp by automation at 4am so its cozy at 8am when we switch to target temp.

but now its getting warmer and we need less boost heating time. how could I set that time in the automation based on the current room temp (below target temp)?

for 3k under target I need 1 hour, for 10K under target I need 8h. for starters I would go with 0,33 * Kelvin2 and the result should be deducted from 8am (thats able to go past midnight on Mondays when the office had time to cool off the whole WE)

Try a Template trigger.

trigger:
  - platform: template
    value_template: >
      {% set target = 295 %}
      {% set k = states('sensor.average_household_temp')|float(0) + 273.16 %}
      {% set hours = (0.33 * (target-k)**2) | round(2) %}
      {% if hours > 8 %}
        {{ now() >= today_at("8:00") + timedelta(days=1) - timedelta(hours=hours) }}
      {% else %}
        {{ now() >= today_at("8:00") - timedelta(hours=hours) }}
      {% endif %}
1 Like

For starters you could just set the thermostat to fixed Room temperature , lets say 15 degree Celsius, then it’s just the outside temperature you have to take in consideration ( thou i don’t see that you include outside temperature as a factor, so i guess, it’s not affecting the Room temperature ) so then it would be a simple equation to warm it to a “cosy” temperature at decided time.

that is a nice piece of logic, thanks.

And even the K numbers are spot on :slight_smile:

So in my automation I have to replace my current

trigger:
  - platform: time
....

for the boost only by your code, right? (and adjust the sensor of course)

could I somehow pull the target temp from the generic thermostat? otherwise I would need to adjust two settings IF I would like change it. Down the road in a year I for sure would forget the one in the automation… :slight_smile: so is there a way to set the values for both positions at the same place once?

in the mean time I try to implement your code…

Thanks

I don’t use generic thermostat (so I might be wrong), but I think that data should be available like this (assuming target_temp is in °C):

trigger:
  - platform: template
    value_template: >
      {% set target = state_attr('climate.YOUR_THERMOSTAT', 'target_temp') | float(0) + 273.16 %}
      {% set k = states('sensor.average_household_temp')|float(0) + 273.16 %}
      {% set hours = (0.33 * (target-k)**2) | round(2) %}
      {% if hours > 8 %}
        {{ now() >= today_at("8:00") + timedelta(days=1) - timedelta(hours=hours) }}
      {% else %}
        {{ now() >= today_at("8:00") - timedelta(hours=hours) }}
      {% endif %}

my whole code looks like this now:

I had to rebuild it via the UI as my system expected a | - instead of the >

alias: SM_heating
description: ''
trigger:
  - platform: template
    value_template: |-
      {% set target = 294.66 %}
      {% set k = states('sensor.buero_temperatur')|float(0) + 273.16 %}
      {% set hours = (0.33 * (target-k)**2) | round(2) %}
      {% if hours > 8 %}
        {{ now() >= today_at("8:00") + timedelta(days=1) - timedelta(hours=hours) }}
      {% else %}
        {{ now() >= today_at("8:00") - timedelta(hours=hours) }}
      {% endif %}
    id: boost
- platform: time
    at: '08:00'
    id: home
  - platform: time
    at: '16:00'
    id: away
condition:
  - condition: time
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
action:
  - choose:
      - conditions:
          - condition: trigger
            id: boost
        sequence:
          - service: climate.set_preset_mode
            data:
              preset_mode: comfort
            target:
              entity_id: climate.buroheizung
      - conditions:
          - condition: trigger
            id: home
        sequence:
          - service: climate.set_preset_mode
            data:
              preset_mode: none
            target:
              entity_id:
                - climate.buroheizung
                - climate.badheizung
      - conditions:
          - condition: trigger
            id: away
        sequence:
          - service: climate.set_preset_mode
            data:
              preset_mode: away
            target:
              entity_id:
                - climate.buroheizung
                - climate.badheizung
mode: single

I took your suggestion and tried it in the dev tools template system, but I cant get a result with this code.

{% set test = state_attr('climate.buroheizung', 'target_temp') | float(0) %}

test: {{test}}

It prints 0 as result, with out float it prints none as result

edit: I made sure I used the right names for the climate and target temp by copy&pasting it from my climates.yaml where it was defined.

Use the Dev Tool> States tool to see if target temp is exposed as an attribute.

Your going to need to allow for pre-midnight Sunday in your conditions

1 Like

no it seams its not, can I change that somehow?

good catch!

edit:

you think this will work?

condition:
  - condition: time
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
  - condition: or
    conditions:
      - condition: time
        weekday:
          - sun
        after: '18:00:00'

Looking through the docs for Generic Thermostat, it looks like it should create a sensor for target temp so check in your sensor entities to see if there’s something that matches.

They need to nest under the OR, otherwise it’s just a long-winded AND :grinning_face_with_smiling_eyes:

condition:
  - condition: or
    conditions:
      - condition: time
        weekday:
          - sun
        after: '18:00:00'
      - condition: time
        weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
1 Like

understood. and thanks for that clarification, that would explain some wired stuff I had with other conditions.

nope, nothing, could this because I did not give them a unique_id? (i just added that and am waiting for the reboot of HA)

That shouldn’t be the reason… the docs say the sensor is a required part of the config, so you must have one. Check your config file and see what you have there under the entry for your thermostat.

you mean the part in the configuration.yaml that regards the thermostat?

this is my code there:

- platform: generic_thermostat
  name: BĂĽroheizung
  unique_id: 46124de8-b4b3-4867-9f11-6a6077f11445
  heater: switch.steckdose_sm_heizung
  target_sensor: sensor.buero_temperature
  min_temp: 10
  max_temp: 24
  ac_mode: false
  target_temp: 21.5
  cold_tolerance: 0.5
  hot_tolerance: 0
  min_cycle_duration:
    seconds: 240
  away_temp: 10
  comfort_temp: 24

So, if you check sensor.buero_temperature in the States tool does it match your current target temperature or is that the actual temp?

no that is the entity providing the current room temperature to the generic thermostat.

what i need in the automation is what is set under target_temp in this case that is 21.5 (°C)

the set target temp is the temperature the generic thermostat is set when HA is rebooted or if the mode is set to “none”, there are other temp pre sets like “away” or in my case “comfort” that are triggered by the automation. so during winter, the thermostat is always in heating = on, but I adjust the temps by the automation. between boost (comfort), normal (none) and nobody-in-office (away)

What about adding an action(s) to you temperature setting automation to store the same value in an input_number helper?