xaviml / controllerx

Create controller-based automations with ease to control your home devices and scenes.
https://xaviml.github.io/controllerx/
MIT License
334 stars 67 forks source link

[FEATURE REQUEST] Detect composite events like double clicks #51

Closed chbndrhnns closed 4 years ago

chbndrhnns commented 4 years ago

Feature Request

I have a couple of Hue Dimmer switches. I would like to detect a double press on a button which is not natively supported.

Is your feature request related to a problem?

For example, in the bathroom, I have motion sensor which cannot see inside the shower. Thus, I'd like to activate a shower mode where the motion sensor is disabled.

Describe the solution / feature you'd like

Have composite events like double press that are not natively supported.

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context or screenshots about the feature request here.

sreknob commented 4 years ago

Hi @chbndrhnns How have you integrated the remote into your setup? Depending on the integration there are different events exposed. ControllerX an only work with what it can see represented from HASS (unless Xavi gets into checking for multiple events). This is something that, if it's still attached to your hue hub, you could get long on/off press functionality through Hue Sensor Advanced custom component. Install the custom component and your remote will be visible in HASS and then you can use ControllerX's state integration to grab a long hold of the top or bottom buttons. Below I have an example for you.

ShowerRemote:
  module: controllerx
  class: CallServiceController
  integration: state
  controller: remote.my_bathroom_hue_remote
  mapping:
    "1_hold":
      service: switch.toggle
      data:
        entity_id: switch.enable_shower_mode
chbndrhnns commented 4 years ago

@sreknob I am trying to understand better. I have no hue bridge in place but a deconz stick. Could the custom component you are mentioning still help me?

Hue remotes in deconz do not show up as sensors in HA but can only be used by listening for their events.

sreknob commented 4 years ago

@chbndrhnns gotcha. No, the custom component won't help for your specific use case. Deconz (and all the other integrations) only report short and long button presses/releases for these remotes. The actual remote only sends these events and the hue bridge must do some event counting to get the specific effects of double and triple tap. You can, however, still use a long button press as is for your event - just add an additional app with the service call you want and the appropriate deconz mapping. Something like this:

ShowerRemote:
  module: controllerx
  class: CallServiceController
  integration: deconz
  controller: bathroom_hue_remote
  mapping:
    1001:
      service: switch.toggle
      data:
        entity_id: switch.enable_shower_mode
xaviml commented 4 years ago

Hi @chbndrhnns

Could you maybe send the event when double clicking? How does deCONZ comunicates that through HA events?

As @sreknob is saying, right now the deconz integration just listens for the event and not anything else. If the double click or triple is sent with a different event id, then it can be handle by ControllerX.

Thank you both for the collaboration :)

chbndrhnns commented 4 years ago

@sreknob I tried this snippet:

livingroom_controller2:
  module: controllerx
  class: CallServiceController
  controller: sensor.office_controller_action
  integration: deconz
  mapping: 
    1002:
      service: switch.toggle
      data:
        entity_id: light.office

and I am seeing this error message:

2020-03-10 09:07:08.213687 WARNING AppDaemon: Unable to find class CallServiceController in module controllerx - 'livingroom_controller2' is not initialized
2020-03-10 09:07:08.218124 WARNING AppDaemon: Unable to find module livingroom_controller2 - initialize() skipped

controllerx is up to date (according to HACS) and I also restarted AppDaemon.

chbndrhnns commented 4 years ago

Hi @chbndrhnns

Could you maybe send the event when double clicking? How does deCONZ comunicates that through HA events?

Double click is no event that deconz exposes. The feature request is about handling this in controllerx in a stateful way, like

In a more general way, this feature is about custom sequences of events which trigger a defined action. But for starters, I would be interested in double click :)

xaviml commented 4 years ago

Hi @chbndrhnns

and I am seeing this error message:

I have seen that error before and it normally appears because there has been an error in the AppDaemon or ControllerX is not properly installed. Could you please share your AppDaemon logs with us to see more in detail what is the problem? Thank you.

xaviml commented 4 years ago

Double click is no event that deconz exposes. The feature request is about handling this in controllerx in a stateful way, like event 1002 comes in -> save event event 1002 comes in again -> compare timestamp to DOUBLE_CLICK_THRESHOLD if within threshold -> perform action defined for double click

This is something I was meaning to do, but I did not plan on doing it yet. I will leave this ticket open for this purpose or I will create a new one with a more detailed and generic description of this feature request. Thank you!

chbndrhnns commented 4 years ago

Here is the log. Nothing strange for me.

If you need debug level, I would welcome a way to switch debug on only for controllerx, otherwise there is loads of logs.

-----------------------------------------------------------
 Add-on: AppDaemon 4
 Python Apps and Dashboard using AppDaemon 4.x for Home Assistant
-----------------------------------------------------------
 Add-on version: 0.2.3
 You are running the latest version of this add-on.
 System: null  (amd64 / qemux86-64)
 Home Assistant Core: 0.106.5
 Home Assistant Supervisor: 209
-----------------------------------------------------------
 Please, share the above information when looking for help
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing...
Log level is set to INFO
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] appdaemon.sh: executing...
Looking in links: https://wheels.hass.io/alpine-3.11/amd64/
Collecting observable>=1.0 (from hass-apps)
  Downloading https://files.pythonhosted.org/packages/45/7c/b4b63f447378e8a0ebcd338d90f9389f57fb23253127425beacf0129edcb/observable-1.0.3-py2.py3-none-any.whl
Collecting cached-property>=1.5.1 (from hass-apps)
  Downloading https://files.pythonhosted.org/packages/3b/86/85c1be2e8db9e13ef9a350aecd6dea292bd612fa288c2f40d035bb750ded/cached_property-1.5.1-py2.py3-none-any.whl
Requirement already satisfied: appdaemon>=3.0 in /usr/lib/python3.8/site-packages (from hass-apps) (4.0.3)
Requirement already satisfied: paho-mqtt in /usr/lib/python3.8/site-packages (from appdaemon>=3.0->hass-apps) (1.5.0)
Requirement already satisfied: pytz in /usr/lib/python3.8/site-packages (from appdaemon>=3.0->hass-apps) (2019.3)
Requirement already satisfied: pyyaml==5.1 in /usr/lib/python3.8/site-packages (from appdaemon>=3.0->hass-apps) (5.1)
Requirement already satisfied: python-dateutil in /usr/lib/python3.8/site-packages (from appdaemon>=3.0->hass-apps) (2.8.1)
Requirement already satisfied: iso8601 in /usr/lib/python3.8/site-packages (from appdaemon>=3.0->hass-apps) (0.1.12)
Requirement already satisfied: astral==1.10.1 in /usr/lib/python3.8/site-packages (from appdaemon>=3.0->hass-apps) (1.10.1)
Requirement already satisfied: aiohttp==3.6.2 in /usr/lib/python3.8/site-packages (from appdaemon>=3.0->hass-apps) (3.6.2)
Requirement already satisfied: aiohttp-jinja2==0.15.0 in /usr/lib/python3.8/site-packages (from appdaemon>=3.0->hass-apps) (0.15.0)
Requirement already satisfied: python-socketio in /usr/lib/python3.8/site-packages (from appdaemon>=3.0->hass-apps) (4.4.0)
Requirement already satisfied: requests>=2.6.0 in /usr/lib/python3.8/site-packages (from appdaemon>=3.0->hass-apps) (2.23.0)
Requirement already satisfied: daemonize in /usr/lib/python3.8/site-packages (from appdaemon>=3.0->hass-apps) (2.5.0)
Requirement already satisfied: pid in /usr/lib/python3.8/site-packages (from appdaemon>=3.0->hass-apps) (2.2.5)
Requirement already satisfied: bcrypt==3.1.4 in /usr/lib/python3.8/site-packages (from appdaemon>=3.0->hass-apps) (3.1.4)
Requirement already satisfied: websocket-client in /usr/lib/python3.8/site-packages (from appdaemon>=3.0->hass-apps) (0.57.0)
Requirement already satisfied: deepdiff in /usr/lib/python3.8/site-packages (from appdaemon>=3.0->hass-apps) (4.2.0)
Requirement already satisfied: yarl==1.1.0 in /usr/lib/python3.8/site-packages (from appdaemon>=3.0->hass-apps) (1.1.0)
Requirement already satisfied: feedparser in /usr/lib/python3.8/site-packages (from appdaemon>=3.0->hass-apps) (5.2.1)
Requirement already satisfied: Jinja2==2.10.1 in /usr/lib/python3.8/site-packages (from appdaemon>=3.0->hass-apps) (2.10.1)
Requirement already satisfied: six>=1.5 in /usr/lib/python3.8/site-packages (from python-dateutil->appdaemon>=3.0->hass-apps) (1.14.0)
Requirement already satisfied: attrs>=17.3.0 in /usr/lib/python3.8/site-packages (from aiohttp==3.6.2->appdaemon>=3.0->hass-apps) (19.3.0)
Requirement already satisfied: async-timeout<4.0,>=3.0 in /usr/lib/python3.8/site-packages (from aiohttp==3.6.2->appdaemon>=3.0->hass-apps) (3.0.1)
Requirement already satisfied: chardet<4.0,>=2.0 in /usr/lib/python3.8/site-packages (from aiohttp==3.6.2->appdaemon>=3.0->hass-apps) (3.0.4)
Requirement already satisfied: multidict<5.0,>=4.5 in /usr/lib/python3.8/site-packages (from aiohttp==3.6.2->appdaemon>=3.0->hass-apps) (4.7.5)
Requirement already satisfied: python-engineio>=3.9.0 in /usr/lib/python3.8/site-packages (from python-socketio->appdaemon>=3.0->hass-apps) (3.11.2)
Requirement already satisfied: idna<3,>=2.5 in /usr/lib/python3.8/site-packages (from requests>=2.6.0->appdaemon>=3.0->hass-apps) (2.9)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/lib/python3.8/site-packages (from requests>=2.6.0->appdaemon>=3.0->hass-apps) (1.25.8)
Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3.8/site-packages (from requests>=2.6.0->appdaemon>=3.0->hass-apps) (2019.11.28)
Requirement already satisfied: cffi>=1.1 in /usr/lib/python3.8/site-packages (from bcrypt==3.1.4->appdaemon>=3.0->hass-apps) (1.14.0)
Requirement already satisfied: ordered-set>=3.1.1 in /usr/lib/python3.8/site-packages (from deepdiff->appdaemon>=3.0->hass-apps) (3.1.1)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/lib/python3.8/site-packages (from Jinja2==2.10.1->appdaemon>=3.0->hass-apps) (1.1.1)
Requirement already satisfied: pycparser in /usr/lib/python3.8/site-packages (from cffi>=1.1->bcrypt==3.1.4->appdaemon>=3.0->hass-apps) (2.19)
Installing collected packages: observable, cached-property, hass-apps
Successfully installed cached-property-1.5.1 hass-apps-0.20200221.0 observable-1.0.3
WARNING: You are using pip version 19.2.3, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[cont-init.d] appdaemon.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[09:19:20] INFO: Starting AppDaemon...
2020-03-10 09:19:27.566682 INFO AppDaemon: AppDaemon Version 4.0.3 starting
2020-03-10 09:19:27.567605 INFO AppDaemon: Python version is 3.8.2
2020-03-10 09:19:27.568414 INFO AppDaemon: Configuration read from: /config/appdaemon/appdaemon.yaml
2020-03-10 09:19:27.568791 INFO AppDaemon: Added log: AppDaemon
2020-03-10 09:19:27.569469 INFO AppDaemon: Added log: Error
2020-03-10 09:19:27.569831 INFO AppDaemon: Added log: Access
2020-03-10 09:19:27.570837 INFO AppDaemon: Added log: Diag
2020-03-10 09:19:27.676517 INFO AppDaemon: Loading Plugin HASS using class HassPlugin from module hassplugin
2020-03-10 09:19:27.799191 INFO HASS: HASS Plugin Initializing
2020-03-10 09:19:27.800094 INFO HASS: HASS Plugin initialization complete
2020-03-10 09:19:27.801354 INFO AppDaemon: Initializing HTTP
2020-03-10 09:19:27.802586 INFO AppDaemon: Using 'ws' for event stream
2020-03-10 09:19:27.837383 INFO AppDaemon: Starting API
2020-03-10 09:19:27.844262 INFO AppDaemon: Starting Admin Interface
2020-03-10 09:19:27.845350 INFO AppDaemon: Starting Dashboards
2020-03-10 09:19:27.865698 INFO AppDaemon: Starting Apps with 10 workers and 10 pins
2020-03-10 09:19:27.887977 INFO AppDaemon: Running on port 5050
2020-03-10 09:19:27.896591 INFO HASS: Connected to Home Assistant 0.106.5
2020-03-10 09:19:27.962427 INFO HASS: Evaluating startup conditions
2020-03-10 09:19:27.991428 INFO AppDaemon: Got initial state from namespace default
2020-03-10 09:19:29.907020 INFO AppDaemon: Scheduler running in realtime
2020-03-10 09:19:29.942208 INFO AppDaemon: Reading config
2020-03-10 09:19:30.055623 INFO AppDaemon: /config/appdaemon/apps/apps.yaml added or modified
2020-03-10 09:19:30.057771 INFO AppDaemon: App 'bathroom_controller' added
2020-03-10 09:19:30.059139 INFO AppDaemon: App 'livingroom_controller' added
2020-03-10 09:19:30.060496 INFO AppDaemon: App 'livingroom_controller2' added
2020-03-10 09:19:30.062253 INFO AppDaemon: App 'bedroom_automoli' added
2020-03-10 09:19:30.063694 INFO AppDaemon: App 'bathroom_automoli' added
2020-03-10 09:19:30.065144 INFO AppDaemon: App 'kitchen_automoli' added
2020-03-10 09:19:30.066552 INFO AppDaemon: App 'livingroom_automoli' added
2020-03-10 09:19:30.068010 INFO AppDaemon: App 'schedy_heating' added
2020-03-10 09:19:30.070140 INFO AppDaemon: Found 8 total apps
2020-03-10 09:19:30.075095 INFO AppDaemon: Adding /config/appdaemon/apps to module import path
2020-03-10 09:19:30.076438 INFO AppDaemon: Adding /config/appdaemon/apps/hue_dimmer_switch_deconz to module import path
2020-03-10 09:19:30.077714 INFO AppDaemon: Adding /config/appdaemon/apps/controllerx to module import path
2020-03-10 09:19:30.079264 INFO AppDaemon: Adding /config/appdaemon/apps/controllerx/core to module import path
2020-03-10 09:19:30.080664 INFO AppDaemon: Adding /config/appdaemon/apps/controllerx/core/integration to module import path
2020-03-10 09:19:30.081930 INFO AppDaemon: Adding /config/appdaemon/apps/controllerx/core/stepper to module import path
2020-03-10 09:19:30.082784 INFO AppDaemon: Adding /config/appdaemon/apps/controllerx/core/type to module import path
2020-03-10 09:19:30.084025 INFO AppDaemon: Adding /config/appdaemon/apps/controllerx/devices to module import path
2020-03-10 09:19:30.084839 INFO AppDaemon: Adding /config/appdaemon/apps/automoli to module import path
2020-03-10 09:19:30.112337 INFO AppDaemon: Loading App Module: /config/appdaemon/apps/hass_apps_loader.py
2020-03-10 09:19:30.120078 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/hello.py - ignoring
2020-03-10 09:19:30.122221 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/deconz_configure_motion.py - ignoring
2020-03-10 09:19:30.124601 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/hue_dimmer_switch_deconz/hue_dimmer_switch_deconz.py - ignoring
2020-03-10 09:19:30.126617 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/const.py - ignoring
2020-03-10 09:19:30.128854 INFO AppDaemon: Loading App Module: /config/appdaemon/apps/controllerx/controllerx.py
2020-03-10 09:19:30.270800 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/core/__init__.py - ignoring
2020-03-10 09:19:30.273347 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/core/controller.py - ignoring
2020-03-10 09:19:30.275226 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/core/integration/__init__.py - ignoring
2020-03-10 09:19:30.277397 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/core/integration/deconz.py - ignoring
2020-03-10 09:19:30.279332 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/core/integration/z2m.py - ignoring
2020-03-10 09:19:30.281598 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/core/integration/zha.py - ignoring
2020-03-10 09:19:30.283674 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/core/stepper/__init__.py - ignoring
2020-03-10 09:19:30.285879 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/core/stepper/circular_stepper.py - ignoring
2020-03-10 09:19:30.287736 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/core/stepper/minmax_stepper.py - ignoring
2020-03-10 09:19:30.289917 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/core/type/__init__.py - ignoring
2020-03-10 09:19:30.291850 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/core/type/light_controller.py - ignoring
2020-03-10 09:19:30.293950 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/core/type/media_player_controller.py - ignoring
2020-03-10 09:19:30.295820 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/devices/__init__.py - ignoring
2020-03-10 09:19:30.298074 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/devices/aqara.py - ignoring
2020-03-10 09:19:30.299886 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/devices/ikea.py - ignoring
2020-03-10 09:19:30.301974 WARNING AppDaemon: No app description found for: /config/appdaemon/apps/controllerx/devices/philips.py - ignoring
2020-03-10 09:19:38.300951 INFO AppDaemon: Initializing app bathroom_controller using class HueDimmerController from module controllerx
2020-03-10 09:19:38.303392 INFO AppDaemon: Initializing app livingroom_controller using class CallServiceController from module controllerx
2020-03-10 09:19:38.305048 WARNING AppDaemon: Unable to find class CallServiceController in module controllerx - 'livingroom_controller' is not initialized
2020-03-10 09:19:38.306260 INFO AppDaemon: Initializing app livingroom_controller2 using class CallServiceController from module controllerx
2020-03-10 09:19:38.308205 WARNING AppDaemon: Unable to find class CallServiceController in module controllerx - 'livingroom_controller2' is not initialized
2020-03-10 09:19:38.448747 WARNING AppDaemon: Unable to find module livingroom_controller - initialize() skipped
2020-03-10 09:19:38.450038 WARNING AppDaemon: Unable to find module livingroom_controller2 - initialize() skipped
2020-03-10 09:19:39.342832 INFO AppDaemon: App initialization complete
xaviml commented 4 years ago

I see that you are missing: /config/appdaemon/apps/controllerx/core/custom_controller.py which is the file that contains the custom controller. Also, I see you are missing lutron.py file. I am guessing you have v2.2.0 installed. Make sure you install v2.3.1 from HACS (then click the "Reinstall" button) and then restart the AppDaemon addon.

Let me know if this worked.

chbndrhnns commented 4 years ago

Then something might be wrong with the installation process. HACS reports v2.3.1 to be installed. I will remove and re-install.

xaviml commented 4 years ago

I have been reported with similar problems and it seems that the "UPDATE" button does not update properly, so the "REINSTALL" button needs to be clicked to make sure it has the version you selected.

I also double-checked right now with HACS 0.23.1 and ControllerX v2.3.1 and the custom_controller.py and lutron.py were downloaded as expected.

chbndrhnns commented 4 years ago

Re-installing controllerx from the HACS panel did it for me, as well.

chbndrhnns commented 4 years ago

Will use the custom controller for me desired behavior

xaviml commented 4 years ago

I am glad it worked @chbndrhnns

I will notify you if I work on the double click feature from ControllerX. Have a great day/evening/night wherever you are :)