I’m moving from another platform (Domoticz) and am really impressed what I can do with HA.
After some steep learning of the automation/scripting and finding a lot of info in this forum and the documentation things work pretty good. But now I’m a bit stuck and can’t find the answer, so here is my problem I hope someone knows how to solve:
To be able to fully move over I would like to have the same functionality I created there to trigger stuff based on remote controls that can sent not only “on”/“off” commands, but also multiple “on” or “off” sequences if you just press the corresponding buttons multiple times. With an automation you can then use this to not have on/off functionality, but also basic dimming.
I now have connected my other system to HA using MQTT and everything works fine if it sends “on” -> “off” state changes, or vice versa. But when I press the remote “on” button 2x times the messages are sent via MQTT to HA, but HA does not seem to register an “update” to the “on” state. So triggering of my script that should handle this does not work.
Question is: how can I get a trigger out of a entity that (via MQTT) gets updated but does not change it’s binary state?
Background how this should work:
The needs to catch the events from a (“KlikAanKlikUit”) remote that I use to dim my lights in steps: with each press of the “on” button on the remote the light need to be turned up by 20% until 100% and then cycles back to 20%. The “off” button, just turns the lights off, and if the lights are “off”, the first press of the “on” button just turns them on.
In this way you can use cheap/simpe remotes that do not support dimming, but only “on” and “off” to control a dimmable light.
I have the automation working in HA by manually triggering, but I can not get it to work to have it triggered by “on” -> “on” events.
You can do the brightness change by templating the light.turn_onservice call.
About the multiple on/off button presses - I guess you’re using this integration?
I’m not too familiar with it sadly.
Try going to the Developer Tools - Events, paste button_pressed and click “Start listening”. Now, press your on button multiple times, does something show up?
The scripting is not so much the problem, I have indeed solved that with templating. And that script works if I just execute it manually.
I’m not using the hardware integration yet, as the remote signals are still being received by Domoticz using an RFX-COM receiver. I have set it up to forward this using MQTT and configured an MQTT switch in HA to get the data into HA.
If I look at the state of this MQTT switch in the developer tools I can see it changing state from “on” to “off” and vice versa, but not from “on” to “on” or from “off” to “off”. Also in the Logbook I see only on -> off events.
So it looks like on -> on and off -> off events are not recorded in HA. Or is that only For MQTT-based switches?
Btw: this is the script, that - as said - works great if triggered manually:
choose:
- conditions:
- condition: state
entity_id: switch.remote_button_1
state: 'off'
sequence:
- service: light.turn_off
target:
entity_id: light.hall
- conditions:
- condition: state
entity_id: light.hall
state: 'off'
sequence:
- service: light.turn_on
target:
entity_id: light.hall
default:
- service: light.turn_on
data_template:
brightness: >
{% set n = states.light.hall.attributes.brightness + 50 %}
{% if n > 255 %}
50
{% else %}
{{ n }}
{% endif %}
entity_id: light.hall
That doesn’t seem to work, just adding this as a trigger:
trigger:
- platform: mqtt
topic: domoticz/out/32
Probably because the MQTT message is not only “on” or “off” it is a Json containing a number of key/value pairs, where “nvalue: 1” or “nvalue: 0” indicates if the button was pushed “on” or “off”.
So therefore this is defined as a switch like this:
Are you referring to leaving out the payload check on the trigger and then checking the state in the condition? That’s what I actually did with the first example:
trigger:
- platform: mqtt
topic: domoticz/out/32
Which then is the trigger to the script I posted earlier, that checks the condition using templating:
choose:
- conditions:
- condition: state
entity_id: switch.remote_button_1
state: 'off'
sequence:
- service: light.turn_off
target:
entity_id: light.hall
- conditions:
- condition: state
entity_id: light.hall
state: 'off'
sequence:
- service: light.turn_on
target:
entity_id: light.hall
default:
- service: light.turn_on
data_template:
brightness: >
{% set n = states.light.hall.attributes.brightness + 50 %}
{% if n > 255 %}
50
{% else %}
{{ n }}
{% endif %}
entity_id: light.hall
But as said: the second part works perfectly if triggered “manually”, but the trigger condition is never met.
No, try adding the MQTT trigger, so it triggers everytime a button is pressed, no matter if on or off, then add a condition, like the one I’ve linked, that checks the MQTT payload, so that your automation only executes the actions when you press the “on” button
Maybe I’m not getting the whole picture here
The domoticz publishes on domoticz/out/32 everytime you press the on button, no matter what you’ve pressed before, correct?
This should now only trigger when pressing the on button, duplicate the automation and use 0 instead of 1 for the “off” version.
Once you get that working, we can take a look at the service calls