HassOS deconz addon missing refresh of sensors

Hi ,

I have installed the marthocoo deconz addon in HassOs and connected a bunch of tradfri lights (7) and aqara temperature sensors (6). At the moment I’m testing the reliability of the setup but notice that refreshes of (at least) the aqara sensors in phoscon are not always synced to hassio. The refresh time stated in phoscon is sometimes newer than the sensor shows in hassio, up to a few hours. It is not a specific sensor, it seems to be random.

System setup:
rpi3b
Hassos 1.12
Conbee stick
marthocoo deconz addon 2.05.47

Is this normal behaviour? If so can the updates be forced to hassos? In case this is not normal behaviour, what could be the cause of it?

Thanx

If it has the same value in hass the update time won’t change. Whereas in deconz they get new values every so often

Aah, that is the reason.

Is it possible to force the update? I use the refresh time of the sensor to check if they are alive. I would like to use the sensors for a thermostat function thus reliability and the alive check is quite important. Do you maybe have other suggestion how to check if sensors are still working properly?

Well they report available, so if the device isn’t available in hass you will know

Thanx. I will try to use that option.

I have tried to use the unavailable option by removing the battery from 1 sensor. Unfortunately sensors seems not to go ‘unavailable’ in phoscon. It will just show refreshed X hours ago ( now already more than 9 hours). For the lights it will show when unavailable.

Any other options that I could try?

Hmm. Next thing would be to ask the deConz guys by opening an issue on their github

thanx again. I opened an issue

I got some feedback from deconz and it seems that ‘unavailable’ state is not that easy to achieve for all zigbee items. IT seems for me that the update time is the only option to check.

To force an update of the sensors even when the state did not change ( in this case temperature) is probably not desired as it could trigger automations etc. For this case it would however be usefull. Any (other) options that I could try?

I use presence detection by checking the deconz websocket port in node red. All sensors report whenever they do in Phoscon. So that’s probably an easy solution if you use node red.

It could be possible to add a new attribute to all deconz entities that shows latest update

@wrenchse : thanx for that solution. The direct link to deconz would be a solution but I am not using node red (yet)…
@Robban : this would be great and for me i think the easiest solution without setting up additional things like node red. How can this be achieved? Can I do something to help?

Hi I found some examples on the forum but it does not work…

A section of my first implementation in AppDaemon as test for all deconz events. It loads the script without any errors and run_every works.

class SaveSensorState(hass.Hass):

def initialize(self):

    start_time = datetime.now()
    self.timeout_length = self.args["check_interval"]
    self.blacklist = self.args["blacklist"].split(",")
    self.whitelist = self.args["whitelist"].split(",")

    try:
        self.device_db = shelve.open(self.args["file"],flag='n')       
    except:
       os.remove(self.args["file"])
       self.device_db = shelve.open(self.args["file"],flag
    # self.listen_state(self.state_change, "sensor") 
    self.listen_event(self.state_change2, "deconz_event")
    self.run_every(self.check_if_updated,start_time, self.timeout_length)


def state_change2(self,event_name, entity,  kwargs):
    self.log("triggered by deconz sensor {}".format(entity))

any ideas why deconz_event does not result in a trigger of state_change2?

@Robban

I am trying to add the lastupdated state from deconz to hassio with limited luck. Could you guide me a bit to find out what is going wrong?

What I tried at the moment:

  1. Found out that listen_event is not working for sensors
  2. Create custom_components for deconz and pydeconz to add the attribute for the deconz state “lastupdated”. I expect that this should be able to work…

Progress so far:

  • created custom_component for deconz and pydeconz.
  • in deconz imported custom pydeconz
    • in deconz/init.py included import custom_components.pydeconz as pydeconz
    • based on some “_LOGGER” entries it seems to load both correctly
  • the deconz "lastupdated’ is a ‘state’ in deconz
  • modified pydeconz/sensor.py with:
    • self._lastupdated = device['state'].get('lastupdated')
    • def lastupdated(self):
  • not working at the moment:
    • when adding a new aqara sensor it is created in Hassio but it seems that sensor.py is not called. I added some “_LOGGER” in class DeconzSensor(DeconzDevice): _init_ and as shown below in class Temperature but none are shown in the log

My question is as I am still trying to learn home assitant and coding: is it something easy to fix or will it take a lot of work and better to wait until it is added in the standard code?

Hereunder the temperature class modification.

class Temperature(DeconzSensor):
    """Temperature sensor.

    State parameter is a string named 'temperature'.
    """

    def __init__(self, device_id, device):
        """Initalize temperature sensor."""
        self._temperature = device['state'].get('temperature')
        self._lastupdated = device['state'].get('lastupdated')
        _LOGGER.error(  "temp init {}".format(self._lastupdated))
        super().__init__(device_id, device)
        self._sensor_class = 'temperature'
        self._sensor_icon = 'mdi:thermometer'
        self._sensor_unit = '°C'
        

    @property
    def state(self):
        """Main state of sensor."""
        _LOGGER.error(  "temp state")
        if self.temperature is None:
            return None
        celsius = round(float(self.temperature) / 100, 1)
        return celsius

    @property
    def temperature(self):
        """Temperature."""
        _LOGGER.error(  "temp_temp")
        return self._temperature

    @property
    def lastupdated(self):
        """last updated."""
        _LOGGER.error(  "temp_update")
        return self._lastupdated

Your changes looks fine, but you can’t use custom components with integrations. What you would have to do is modify the real hass files.

Last thing function wise would be to add a new attribute to the sensor that reads the lastupdated

Thanx. I’m doubting if I want to modify the original hass files and logging into docker. This will interfere with updates of hassos, I think? Maybe it it is wise to just accept the senosr udate limitation…

Long term I can add this to the component. Or you can create a PR.

Im busy with other stuff and I prefer not to do more development tasks in parallell in order to preserve focus.

I’m struggling with this problem too: I have no idea is my water leak sensor alive or not. Is there a PR created for adding last updated information to sensor attributes? This way everyone - depending on the use case - can determine when a sensor is considered to be unavailable.

If it is truly unavailable deconz will tell hass and hass will mark it as unavailable

What means “truly”? I removed the battery of the sensor and after 9 hours it is still available. This is not acceptable for sensor that should alert a water leak. Acceptable would be something like 5-30 minutes. Even then unavailability wouldn’t always tell wether the sensor is out of coverage from time to time. Note that water sensor is often in difficult places from radio point of view; under machines, closets, etc.