Home assistant and AppDaemon delay

Hi
I have 2 Hue dimmer and 3 Lumi buttons. The Hue dimmers are connected to the Hue bridge and Lumi buttons are connected to RaspBee/deConz running on same Pi3+ as Home assistant.

I’m experience some strange behaviour where every 10-20 button event is an “echo” of the last event. I removed all my REST sensors from HA, other than my 5 buttons (2x5 sensors in total), since i was getting a lot of “Updating rest sensor took longer” warnings. That gave less warnings (still get a few), but did not remove the “echo”.
The quick fix to my problem is adding a two second delay from the button lastupdated state triggers to when AppDaemon check the state of button event sensor in HA.

Any have the same experiences? I got more sensors in deConz i want to monitor/use. But that will either give more delay issues in AP and/or flood the log with “Updating rest sensor took longer” in HA.

HA is connecting to deConz on localhost, so network latency shouldn’t be an issue.

Regards
/Lars

button.yaml

button_sov:
  module: button_action
  class: ButtonOnOff
  event_trigger: sensor.btn_sov_lastupdated
  button_event: sensor.btn_sov_event
  action:
    - 1002,light.sov_natlampe
    - 1004,group.all_lights

button_action.py

import appdaemon.plugins.hass.hassapi as hass
import time

class ButtonOnOff(hass.Hass):
    """Button On / Off"""
    def initialize(self):
        self.verbose = True
        self._verbose("Button OnOff Init")

        if "event_trigger" and "button_event" and "action" in self.args:
            self.listen_state(self._button_action, self.args["event_trigger"])
        else:
            self.log("No button event/trigger and action specified")

    def _verbose(self,msg,status=False):
        """Log, if self.verbose"""
        if status or self.verbose:
            self.log(msg)

    def _button_action(self, entity, attribute, old, new, kwargs):
        """Turn on/off unit on button action"""
        time.sleep(2) # ..:: QUICK FIX ::..
        btn_event = self.get_state(self.args["button_event"])
        for entity in self.args["action"]:
            event = self.split_device_list(entity)[0]
            light = self.split_device_list(entity)[1]
            if btn_event == event:
                light_state = self.get_state(light)
                if light_state == "off":
                    self._verbose("Turn on %s (btn event %s)" % (light,event))
                    self.turn_on(light)
                else:
                    self._verbose("Turn off %s (btn event %s)" % (light,event))
                    self.turn_off(light)

HomeAssistant - rest sensor

- platform: rest
  resource: !secret lumi_btn_sov
  name: btn_sov_event
  value_template: '{{ value_json.state.buttonevent }}'
  scan_interval: 1

- platform: rest
  resource: !secret lumi_btn_sov
  name: btn_sov_lastupdated
  value_template: '{{ value_json.state.lastupdated }}'
  scan_interval: 1

May I ask you why you didn’t connect the hue dimmers to deconz as well? Could you please also explain why you use a rest sensor for the lumi buttons? Couldn’t you just simply catch the event directly in AppDaemon with self.listen_event?

May I ask you why you didn’t connect the hue dimmers to deconz as well?
I want to make sure certain things work properly before move away from the Hue bridge

Could you please also explain why you use a rest sensor for the lumi buttons? Couldn’t you just simply catch the event directly in AppDaemon with self.listen_event ?
I wasn’t aware of I could listen direct for the deConz event. I tested it quick and I will definitely look into that, thanks.
Any other thoughts regarding HA/deConz? I Got a couple of Hue motion sensor I’m hesitating to move over.

I understand, sounds reasonable to test everything first before ditching the Hue bridge completely.

I moved all my Hue devices over to deConz and ditched the hub. I never looked back, everything responds immediately and I get button presses from the dimmer instantly. In case you have any questions feel free to ask.

Hi Burningstone, I hope you can help me.
I moved everything to deCONZ yesterday and it seems to work. But how do I find the button events from my wall switches, in Hass.io?
I have Xiaomi Aqara double wall switches, Vimar double wall switches and Philips HUE dimmer switches.

Sure. Go to Developer Tool -> Events

In the section “listen_events” enter “deconz_event” and press “start listening”. Now when you press a button you see the event there.

2 Likes

Wow, that was a fast answer. And now I see the events.
Thank you very much.