SOLVED. Intelligent thermostat algorithm needed. Guru needed

Wow ! you deserve a medal
:+1: :1st_place_medal:

Mind you Iā€™m not the the in charge of leaving doors and windows open around here so it can get messy.

Yep you could do that, Iā€™d do a date change (or maybe noon each day depends when you wish to sample temperatures) then adjust your input number based on that difference (youā€™ll probably need to have ann ā€˜offsetā€™ added to the mix)
Just create a template sensor, test the outside_sensor against these limits and output the result.
Do you need help with that ?
Better still (based on your last post) fire an automation at the same time everyday then write the result to an input_number
Again, do you need help or are you okay from here ?

So in your case ā€¦
The reason Iā€™d go with a 10 minute base cycle is a) to bisect your 15 minute update every ā€˜otherā€™ time (lessened if you go with brahmafearā€™s suggestion of extra sensors, so Iā€™d coincide with the sensor update values (as this will save Valve Motion thus Batteries) @15 mins

either way you owe a debt of thanks to : -
@brahmafear , @CaptTom , @Sand and @tosion

Confused now!

So you mean in my case, do you mean an initial ā€˜mark-timeā€™ of 10 minutes , or a duty-cycle of 10 mins?

My ā€œsensorsā€ are the eTRVs. Not obvious to me as to why I would go and procure another 6 thermostats? The eTRVs do this job, or supposed to - granted not as well perhaps as 6 wall thermostats , but this is the entire reason for the OP? I have eTRVs in 6 rooms but I would not want to use these to aggregate some overall measure because each room is heated to a different setpoint.
This brings me to the reason for confusion. I did admittedly set out to simply things above by using a single eTRV and use suggestions around duty-cycle and monitoring to adjust future duty-cycle durations. However, I actually have 6 eTRVs each at different setpoints and each driving the same single boiler in the home. So actually, it isnā€™t straight forward because of course any given duty-cycle will be heating mutliple rooms to different setpoints. Iā€™m confused now as to how to deal with this. It was easy-ish when using a single eTRV, one duty-cycle, one mark-timer, and a single heating demand with a single boiler.
Head hurts :roll_eyes: :grimacing: Not sure what to do now.
Thank you to all the inputs by the way @tosion @CaptTom @brahmafear @Mutt @Sand but prob need more input/ideas on this.

Oh, thanks a lot! As a noob I am embarrassed here. And actually the accuracy is 0ā€¦+0,2 C :wink:

But yes I would like to get help here, I am so beginner in coding. I use as an outside temperature sensor:

sensor.ulko_temppi

So the question is how to replace that 6 minutes below with a variable based of the value of that sensor.ulko_temppi?

- id: Varastoheat_off_2
  alias: Varastoheat_off_2
  trigger:
    platform: state
    entity_id: switch.mvarastoplug
    to: 'on'
    for:
      minutes: 6
  action:
    service: homeassistant.turn_off
    entity_id:
      - switch.mvarastoplug

I would appreciate a lot if someone could help me out with this?

Template the minutes key/pair

automation:
  trigger:
    - alias: Varastoheat_off_2
      platform: state
      entity_id: input_boolean.varastoheat
      to: 'on'
      for: 
        minutes: "{{ states('sensor.ulko_temppi') }}" #-- assumes ulko_temppi is minutes!
      action: ..
..
..

Sorry,

sensor.ulko_temppi

is a temperature sensor. And based on its value the delay should be adjusted (just an rough example):

< - 20 C -> 15 min
< - 15 C -> 12 min
< - 10 C -> 10 min
< - 5 C -> 8 min
< 0 C -> 6 min
more than 0 -> 4 min

automation:
  trigger:
    - alias: Varastoheat_off_2
      platform: state
      entity_id: input_boolean.varastoheat
      to: 'on'
      for: 
        minutes: >
          {% if states('sensor.ulko_temppi') > 0.0 %}
            {{ 4 }}
          {% elif 0.0 < states('sensor.ulko_temppi') < -5.0 %}
            {{ 6 }}
          {% eif -5.0 < states('sensor.ulko_temppi') < -10.0 %}
            {{ 10 }}
          ..  you get the idea ..
          {% endif %}
      action: ..

EDIT

p.s. your logic needs tweaking as your comparators do not account for equality.
For example, what if the sensor is 0.0 ? Your logic doesnt account for this. It only considers >0 or <0 but not 0. Same for other temps. Adjust the template code I gave - accordingly - but assuming these are linear levels as in +4 ā€¦ 0 ā€¦ -5 ā€¦ -10 then I would suggest:

          {% if states('sensor.ulko_temppi') >= 0.0 %}
            {{ 4 }}
          {% elif 0.0 < states('sensor.ulko_temppi') <= -5.0 %}
            {{ 6 }}
          {% eif -5.0 < states('sensor.ulko_temppi') <= -10.0 %}
            {{ 10 }}
          ..  you get the idea ..
          {% endif %}

Back to my problem. Iā€™m stuck guys with the logic given 6 eTRVs I have and that they all output their own heat demands via generic_thermostat component, and the endpoint for all these is a single boiler switch. Help ! :slight_smile:

Many thanks!

Looks good! Couple stupid questions:

  1. Is there a way to do equal or greater (when temperature is 5.0 C even) Does this work?
=<
  1. What might happen if outside temperature is changing ā€œduring the delayā€?

But yes, thanks a lot!

EDIT: you already answered to my first question, thanks!

sorry, editing my post as you sent yours. see my previous post.

Not sure what you mean - sorry? The temperature will always be changing will it not, it depends on the resolution of your sensor. For example, if the resolution is 0.0000001 then it is ā€˜foreverā€™ going to change , is it not?

I meant as an example. If ā€œforā€ starts to ā€œcountā€ 4 minutes when outside temperature is +0.1 C and when during the counting outside temperature changes to -0.1 C.

Does it stop after 4 minutes or 6 minutes or at all? Do you understand what I mean?

Good question. The trigger should be reset to start counting again if the change is across the boundaries, for example from +0.1 to -0.1 will start counting again for 6 minutes (when it was counting for 4 previously). Programmatically I would not expect the previous ā€œticksā€ to count toward the ā€œforā€. However, I am unsure as to whether this is how it actually operates. Logic deduction does not necessarily mean that is how the world functions ! :slight_smile:

If this is undesired, then you would need a different template probably better using the template platform and using a template_value. in fact, this is probably more prudent than my original suggestion - in environments where your sensor is changing as described.

  - alias: mark_space_update
    mode: single
    max_exceeded: silent
    trigger:
      - platform: time_pattern
        minutes: '/30'
    action:
    - service: input_number.set_value
      data_template:
        entity_id: input_number.mark_number
        value: >
          {% set temp = states('sensor.ulko_temppi') | float %}
          {% if temp >= 0 %}
            4
          {% elif temp >= -5 %}
            6
          {% elif temp >= -10 %}
            8
          {% elif temp >= -15 %}
            10
          {% elif temp >= -18 %}
            12
          {% else %}
            15
          {% endif %}

Your numbers donā€™t seem to match up but by adding an extra threshold you can get them in, the point is as ninjaef says - you get the idea (but the above is ā€˜leanerā€™ than ninjaefā€™s

The value ā€˜kicks inā€™ as the ā€œfor: valueā€ when the trigger for that happens so you can update every 30 seconds if you want, it wonā€™t care (the time is then set in concrete).

NOTE: You ALWAYS need an ELSE to complete an IF but you can have 0 to 1000ā€™s of elifā€™s as long as they march in the same direction

1 Like

Indeed it is. I was overcooking the egg to remove doubt, and the set you introduced adds to overall performance improvement - agreed.

Any ideas on my OP and logic - Iā€™m lost now. :upside_down_face:

Thanks again!

I real life I think this would be a minimal problem. I think it would be very rare and on the other hand if in this example case the switch would be on max 10 minutes (instead of 4 or 6). It would not be a disaster.

The other sensors may update quicker is all I meant.(see ā€˜*ā€™ later)

Determining if your boiler should be on or not : -
UK heating systems have a bypass (or should to be ā€˜legalā€™) this may result in one of your rooms getting hotter than the rest
Donā€™t these eTRVā€™s try to modulate to achieve the ā€˜set temperatureā€™ ??? (ā€™*ā€™ Iā€™m really confused about how these valves operate, thereā€™s conflicting information here)

The other classic way of doing this is monitor each sensor value, either average them or take highest or take mid point between those two. use that as the ā€˜sensor valueā€™ for a generic thermostat (software based) and output that to a template switch, have another automation turn on the boiler if your mark space and the template switch are both ā€˜onā€™ (the ā€˜mark-endā€™ of this is the bit you monitor to adjust the mark-space)

Note: will be AFK for about 2 hours

Xcept that the mark-space should start at the point the boiler comes on so the automation will have to cater for the exception

Thanks for coming back to the OP - appreciated.

They all are set as an immutable 15min tx periods but the phasing will for sure be different as they were not all powered up at the same time.

They get hotter because the eTRVs do not completely close off the valve (another issue). Also rooms heat up at varying levels of speed because other parameters are at play such as room size, compass direction of room (i.e. south rooms warm up quicker than north) , radiator size, time of day, and so on - as I alluded to in my OP.

This is a prudent insightful suggestion. I will scribble out some ideas on paper.

Can you elaborate please , Iā€™m not grasping the concept / your terminology.

Thank you both @ninjaef @Mutt very much for excellent help. I am sorry I can not help OP too much.

My English is definitely not from London, so I have to try my best to understand everything I am reading - so my stupid question here still is:

The value ā€˜kicks inā€™ as the ā€œfor: valueā€ when the trigger for that happens so you can update every 30 seconds if you want, it wonā€™t care (the time is then set in concrete).

Do I understand correctly here - the right answer in this case is 6 minutes? :wink:

Correct! that is my understanding.- sort of (!) - because the automation mode will define what the outcome will be. Read onā€¦

As @Mutt asserts, the trigger event is processed each time the event occurs. However I would elaborate on what @Mutt mentions because it isnā€™t so cut and clear. An important clarification is that how the triggers are handled is user defined by you using the mode: key/value pair (Automation Mode). Read onā€¦

If you have a trigger condition then the code is executed when the trigger condition is met.

If the trigger event is fired multiple times then they are honoured in a certain way - which can be configured. For example one can have multiple ā€œstackedā€ responses to triggers processed in chronological order , or each triggered event can ā€œreplaceā€ the previous event. Called ā€œAutomation Modesā€ (see below). You can thus enforce whatever you want in terms of how your automation will respond to changes in your outside sensor. For example, set mode: restart to restart your for: counter each time the outside temp changes - if that is what you want. Other mode values can change this behaviour. My impression is that you need to set a mode because the default does nothing but issue a warning into /config/homeassistant.log file.
Each time your outside temp changes, as you suggest it will, then changes in outside temp within 4 , 6 (or whatever) seconds are going to be processed according to the mode , so think about it and set it explicitly. I still abide by the golden rule I learnt back in the 1970s coding in Z80A assembler:- In software, never assume anything !!

Itā€™s all explained as per link above, and othersā€¦



Thank you for the clarification!

I am a curious about your heating system in OP . I am not familiar with British heating systems, but basically you have hot water circulating in 6 radiators with those thermostats (honestly I did not quite understand the system). Which part you are trying to control with HA. The water temperature (some water heater)? Doesnā€™t those thermostats control them self the amount of hot water in each radiator based on set value in the thermostat? And the thermostat itself has the temperature sensor included and that value is transported to HA in every 15 minutes? So is the only thing you will control with HA the water heater? Right? Or is there a way to control the valve in radiator?

Am I on the map at all? :wink: