hthiery / python-fritzhome

Python Library to access AVM Fritz!Box homeautomation
MIT License
52 stars 37 forks source link

Thermostat Offset #71

Closed mietzen closed 1 year ago

mietzen commented 1 year ago

Is / Would it be possible to control the thermostat offset value? This would enable users to use cheaper sensors to calibrate their AVM thermostats.

image

mietzen commented 1 year ago

I will try to implementing it myself,I poked around with wireshark and discovered post request to http://fritz.box/net/home_auto_hkr_edit.lua Containing the following keys:

sid=00000
device=25
view=
back_to_page=sh_dev
ule_device_name=My-Device
Heiztemp=19
Absenktemp=17
graphState=1
timer_item_0=0830%3B1%3B127
timer_item_1=1830%3B0%3B127
Holidaytemp=18.5
Holiday1StartDay=1
Holiday1StartMonth=5
Holiday1StartHour=0
Holiday1EndDay=31
Holiday1EndMonth=5
Holiday1EndHour=23
Holiday1Enabled=1
Holiday1ID=1
Holiday2StartDay=22
Holiday2StartMonth=12
Holiday2StartHour=16
Holiday2EndDay=5
Holiday2EndMonth=1
Holiday2EndHour=15
Holiday2Enabled=0
Holiday2ID=2
Holiday3StartDay=22
Holiday3StartMonth=12
Holiday3StartHour=16
Holiday3EndDay=5
Holiday3EndMonth=1
Holiday3EndHour=15
Holiday3Enabled=0
Holiday3ID=3
Holiday4StartDay=22
Holiday4StartMonth=12
Holiday4StartHour=16
Holiday4EndDay=5
Holiday4EndMonth=1
Holiday4EndHour=15
Holiday4Enabled=0
Holiday4ID=4
HolidayEnabledCount=1
SummerStartDay=1
SummerStartMonth=6
SummerEndDay=15
SummerEndMonth=9
SummerEnabled=1
WindowOpenTrigger=4
WindowOpenTimer=90
tempsensor=own
Roomtemp=19
ExtTempsensorID=tochoose
Offset=-2
validate=apply
xhr=1
useajax=1

I guess we would need a new request function specific for thermostat. But this would give us much more setters: Hollidays, Temp Schedules, Window Open Timer, Offset, etc. I'll try to write a POC over the holidays, but no promises.

@hthiery is /webservices/homeautoswitch.lua the mobile app API? Why did you pick this one over the device specific ones?

flabbamann commented 1 year ago

Hi @mietzen,

see the developer documentation here: https://avm.de/service/schnittstellen/ This Library uses the AHA HTTP Interface

I'm afraid this does not offer a method to set the offset 🙁

But wouldn't this be a one time action you could set via the Fritzbox Web interface and then you are good to go? Or maybe I don't understand your use case 😉

mietzen commented 1 year ago

image

This is a graph of the last days from one of my rooms. Blue is the thermostat, magenta is the temperature sensor. The radiator and hence the thermostat are mounted underneath the window on the only outer wall of the room. I corrected the offset to have a good fit during day times. Over night the central heating goes into night mode and in cold nights we get a huge temperature gradient between the outer wall and the middle of the room. This is mainly due to improper insolation of the walls (Rented house, construction year 1997 -.-). This leads the thermostat to think it has to open the valve to 100% the whole night and as soon as the central heating delivers any heat, we experience a massive overshoot in the night / morning.

Something I discovered the last days, is that also the offset during the day isn't constant, it depends on the outside temperature (Dec 20th). Which makes sense since the radiator is loosing way less energy on the outer wall and is heating the room more efficiently.

So the offset has to be changed at least 2 times a day, especially if you live in a older house.

Gezzo42 commented 1 year ago

I had a similar problem: The thermostat measure a fare to high temperatur during heating. Therefore I use another sensor in combination with this thermostat. Everything is integrated in www.home-assistant.io. Dependending on the measured temperatur the thermostat temperatur is resetted. If you are interested in more details, I can give you the automation.

mietzen commented 1 year ago

I had a similar problem: The thermostat measure a fare to high temperatur during heating. Therefore I use another sensor in combination with this thermostat. Everything is integrated in www.home-assistant.io. Dependending on the measured temperatur the thermostat temperatur is resetted. If you are interested in more details, I can give you the automation.

Thats sounds like a good workaround 👍 It would be awesome if you post the automation!

Gezzo42 commented 1 year ago

So here is my home assistant automation for my Fritz!DECT 301 thermostat. It needs a additional temperatur sensor (here: sensor.wohnzimmer_temperature) and a number from the helper area (input_number.zieltemperatur).

alias: Temperatur Regelung
description: ""
trigger:
  - platform: state
    entity_id: climate.wohnzimmer
    attribute: current_temperature
condition:
  - condition: not
    conditions:
      - condition: device
        device_id: c2094fa2748c6076b35f021cff65e09b
        domain: climate
        entity_id: climate.wohnzimmer
        type: is_preset_mode
        preset_mode: eco
action:
  - service: climate.set_temperature
    data:
      temperature: >-
        {% if state_attr('climate.wohnzimmer','current_temperature')|float <
        states('input_number.zieltemperatur')|float %}
          {{ states('input_number.zieltemperatur')|float + 2}}
        {% else %}
          {{ (states('input_number.zieltemperatur')|float +
            (state_attr('climate.wohnzimmer','current_temperature')|float -
            states('sensor.wohnzimmer_temperature')|float))|round(1, "half") }}
        {% endif %}
    target:
      entity_id: climate.wohnzimmer
mode: single
mietzen commented 1 year ago

As promised: https://github.com/mietzen/python-fritz-advanced-thermostat

The library is only an extension to fritzhome and doesn't replicate any of it's functionality. I made it a separate library since I think my approach is way to hacky to be integrated within fritzhome.

Nevertheless now I got a way to use my aqara sensors to set the offset. I only need to write a HA AppDeamon automation. If I find some time I will also implement the setter and getter for holidays, lock and summer events.

If anyone is interested in the HA AppDeamon automation, I will edit this post and add a link to it as soon as it's ready.