Update current temperature for Z-Wave thermostats

Some Z-Wave radiator thermostats like Danfoss 014G0013 don’t report the temperature to the controller and Home Assistant displays the current temperature as none. I wrote a small python script that takes the temperature value from the specified sensor and fills the thermostat state with each thermostat and temperature change.
This isn’t an elegant solution but it works. Maybe someday someone with real python skills will add this feature to the climate/zwave component.
Download script

thermostat_id  = data.get('thermostat')
sensor_id  = data.get('sensor')

if thermostat_id != "" and sensor_id != "":
   sensor = hass.states.get(sensor_id)
   temp = sensor.state
   if temp is not None and temp is not "Unknown":
      thermostat = hass.states.get(thermostat_id)
      attributes = thermostat.attributes.copy()
      attributes['current_temperature'] = temp
      hass.states.set(thermostat_id, thermostat.state, attributes)
else:
   logger.error("Wrong data.")

To run this script you have to use service python_script with thermostat and sensor entity_id as data.

service: python_script.thermostat_current_temp
  data:
    thermostat: climate.thermostat_kuchnia_heating_1
    sensor: sensor.temperature_kuchnia

In my configuration I have names of sensors and thermostats according to the pattern:

climate.thermostat_NAME_OF_THE_ROOM_heating_1
sensor.temperature_NAME_OF_THE_ROOM

that’s why I could apply quite simple automation to the script:

- id: heating_update_current_temperature
  alias: 'Heating Update Current Temperature'
  trigger:
    platform: state
    entity_id:
      - sensor.temperature_antek
      - sensor.temperature_salon
      - sensor.temperature_kuchnia
      - sensor.temperature_antresola
      - sensor.temperature_sypialnia
      - sensor.temperature_lazienka
      - climate.thermostat_antek_heating_1
      - climate.thermostat_kuchnia_heating_1
      - climate.thermostat_salon_heating_1
      - climate.thermostat_antresola_heating_1
      - climate.thermostat_sypialnia_heating_1
      - climate.thermostat_lazienka_heating_1
  condition:
    condition: template
    value_template: >-
      {% if "thermostat" in trigger.entity_id and trigger.to_state.attributes.current_temperature == none %}
         true
      {% elif "sensor" in trigger.entity_id %}
         true
      {% else %}
         false
      {% endif %}
  action:
    service: python_script.thermostat_current_temp
    data_template:
      thermostat: >-
         {% if "thermostat" in trigger.entity_id %}
            {{ trigger.entity_id }}
         {% else %}
            climate.thermostat_{{ trigger.entity_id | replace('sensor.temperature_', '') }}_heating_1
         {% endif %}
      sensor: >-
         {% if "sensor" in trigger.entity_id %}
            {{ trigger.entity_id }}
         {% else %}
            sensor.temperature_{{ (trigger.entity_id | replace('climate.thermostat_', '')) | replace('_heating_1', '') }}
         {% endif %}

- id: heating_update_current_temperature_at_start
  alias: 'Heating Update Current Temperature At Start'
  trigger:
    platform: homeassistant
    event: start
  action:
    - service: python_script.thermostat_current_temp
      data:
        thermostat: climate.thermostat_antek_heating_1
        sensor: sensor.temperature_antek
    - service: python_script.thermostat_current_temp
      data:
        thermostat: climate.thermostat_kuchnia_heating_1
        sensor: sensor.temperature_kuchnia
    - service: python_script.thermostat_current_temp
      data:
        thermostat: climate.thermostat_salon_heating_1
        sensor: sensor.temperature_salon
    - service: python_script.thermostat_current_temp
      data:
        thermostat: climate.thermostat_antresola_heating_1
        sensor: sensor.temperature_antresola
    - service: python_script.thermostat_current_temp
      data:
        thermostat: climate.thermostat_sypialnia_heating_1
        sensor: sensor.temperature_sypialnia
    - service: python_script.thermostat_current_temp
      data:
        thermostat: climate.thermostat_lazienka_heating_1
        sensor: sensor.temperature_lazienka

And this is the resault:
thermostat

10 Likes

Great work! Will this make HA control the valve of the LC-13 to reach the desired target temperature by comparing with the input from the defined external temp-sensor?

Great! I felt really stupid when I realized the temperature wasn’t reported, now a lot less so!

Pity, homebridge wasn’t fooled though…
/Johan

No, the script only adds a temperature value from sensor to the thermostat current_temperature attribute. The thermostat works completely alone on the basis of its own temperature measurements and HA can’t interfere with it beyond the target temperature change.

Vote for this feature Combine Danfoss 014G0013 thermostat and other temperature sensor to show current temperature if you want this as a standard in HA.

Did you already found a solution to get the current temp. in homebridge? I have the same problem.

Sort of. I have a Telldus znet for my 433 devices. I moved my Danfoss there, used this https://forum.telldus.com/viewtopic.php?f=31&t=6587&sid=36ba247e7b019d9e12f3480f92df5b0a&start=15 and hass generic thermostat. Works perfect, but I believe @Bieniu idea is better still.

/Johan

If someone prefers a script for AppDaemon then you can use this.

It also changes the thermostat status “unknown” to “heat” or “idle” depending on the target temperature.
image

1 Like

That’s great! How can i use it? I get the following error; 2018-03-06 18:58:53.606731 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/update_thermostats.py - ignoring

I added the .py script in the config\appdaemon\apps folder and restarted appaemon?

Thank you!

You have to add to apps.yaml thermostats and sensors entities. The order of thermostats and sensors is important. The first thermostat takes data from the first sensor, the second thermostat from the second sensor, etc.

update_thermostats:
  module: update_thermostats
  class: UpdateThermostats
  thermostats:
    - climate.thermostat_kuchnia
    - climate.thermostat_salon
    - climate.thermostat_antresola
    - climate.thermostat_sypialnia
    - climate.thermostat_lazienka
    - climate.thermostat_antek
  sensors:
    - sensor.temperature_kuchnia
    - sensor.temperature_salon
    - sensor.temperature_antresola
    - sensor.temperature_sypialnia
    - sensor.temperature_lazienka
    - sensor.temperature_antek

Thanks for your help Bieniu,

I’ve changed the apps.yaml with the correct name of the LC-13 and one of my temp sensors, but get the following error;

2018-03-07 08:12:41.236338 WARNING AppDaemon: ------------------------------------------------------------
2018-03-07 08:12:41.237605 WARNING AppDaemon: Unexpected error running initialize() for update_thermostats
2018-03-07 08:12:41.238701 WARNING AppDaemon: ------------------------------------------------------------
2018-03-07 08:12:41.242663 WARNING AppDaemon: Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/appdaemon/appdaemon.py", line 1495, in init_object
init()
  File "/config/appdaemon/apps/update_thermostats.py", line 12, in initialize
if self.check_entity(self.args['thermostats'][i]) == False:
  File "/config/appdaemon/apps/update_thermostats.py", line 63, in check_entity
while not (self.entity_exists(entity) or n > 120):
AttributeError: 'UpdateThermostats' object has no attribute 'entity_exists'
2018-03-07 08:12:41.243686 WARNING AppDaemon: ------------------------------------------------------------

update_thermostats:
  module: update_thermostats
  class: UpdateThermostats
  thermostats:
    - climate.danfoss_z_thermostat_014g0013_heating_1
  sensors:
    - sensor.fibaro_system_fgsd002_smoke_sensor_temperature

Very strange. Which version of AppDaemon do you use?

I’m using version 3.0, should i try 2.0?

Honestly, I don’t know what changes were introduced in 3.0. I use 2.1.12. If you can try version 2.x.

I use it with 3.0 and it works great. I made a few changes to fit my needs but the changes are only minor. As the lines in your errors don’t seem to match the most recent version on github, could you pastebin your version to get a better insight?

@Bieniu great work by the way. I just “upgraded” to your most recent version from github and implemented my changes.

1 Like

@cgtobi I’m curious what changes you made?

@Bieniu sure, no problem. I only made it work with 3.0 and slightly modified the behaviour when the thermostat displays idle or heat.

1c1
< import appdaemon.appapi as appapi
---
> import appdaemon.plugins.hass.hassapi as hass
27c27
< class UpdateThermostats(appapi.AppDaemon):
---
> class UpdateThermostats(hass.Hass):
53c53
<                 self.find_thermostat_state(float(target_temp))
---
>                 self.find_thermostat_state(float(target_temp), float(sensor_temp))
68c68
<                 self.find_thermostat_state(float(target_temp))
---
>                 self.find_thermostat_state(float(target_temp), float(current_temp))
73,74c73,74
<     def find_thermostat_state(self, temperature):
<         if temperature > 8:
---
>     def find_thermostat_state(self, target_temp, current_temp):
>         if round(current_temp) < round(target_temp):
87a88
> 
1 Like

Just to double check: are you talking about this ‘unknown’ state?

grafik

Exactly. Just like this:

grafik