@Koenkk currently only "click" is reportet to the aqara button sensor state in home assistant.
So only "single", "double" can be reportet to the state.
I use (because of the issue, only works after 1-2 seconds after triggered, you know what I mean)
trigger:
platform: mqtt
topic: 'zigbee2mqtt/ZigbeeButton'
condition:
- condition: template
value_template: '{{ "hold" == trigger.payload_json.**action** }}'
For click is looks like this
trigger:
platform: mqtt
topic: 'zigbee2mqtt/ZigbeeButton'
condition:
- condition: template
value_template: '{{ "single" == trigger.payload_json.**click** }}'
So I don't need this, but I noticed it and might be necessary for other users, that want to use the "hold" feature that is reportet in "action" not in "click".
not sure this is an "issue" :) ... curious, what does the asterix's in **click** and **action** do in HA?
or is it supposed to be how i have it value_template: "{{ value_json.click }}" and you wanted to bold the click and action?
also note you can add:
json_attributes:
- "battery"
- "voltage"
- "linkquality"
- "last_seen"
Sry for the * *
Ignore them
I wanted to make them bold
I think json_attributes is obsolete.
It got replaced by json_attribute_topic if I remember it right.
I think json_attributes is obsolete.
It got replaced by json_attribute_topic if I remember it right.
Not in then sensor: section... this works for me. How else would you setup the buttons? I have them as sensors.
I have my devices autodiscovered. So I don't set them up manually.
I think json_attributes still work for mqtt sensors, but they are deprecated.
See here
https://www.home-assistant.io/components/sensor.mqtt/
json_attributes_topic
(string)(Optional)The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes.
json_attributes
(list | string)(Optional)(Deprecated, replaced by json_attributes_topic) A list of keys to extract values from a JSON dictionary payload and then set as sensor attributes.
You will see a warning in your logs
@marc-gist , can you please show an example of automation with the sensor definition and
json_attribute_topic?
I don't thing that he uses
json_attribute_topic
What do you mean with "automation with the sensor definition and json_attribute_topic?"
Do you mean configuration instead of automation? So an example how to use json_attribute_topic in a sensor?
If so simple add the topic name like you know it from
state_topic: "some/mqtt/topic"
json_attribute_topic: "some/mqtt/topic"
in this format.
yes, configuration for the mqtt sensor and automation example
Search for your device here
https://www.zigbee2mqtt.io/integration/home_assistant.html
You can find your devicename here
https://www.zigbee2mqtt.io/information/supported_devices.html
for the aqara button it would be WXKG11LM or WXKG12LM
and simply add the line as I mentioned above.
Indeed, this particular aqara buttons peculiarity ruins intuitive and seamless writing of automation. IMHO, action-to-state reposting should be done on the Z2M side for this device.
Indeed, this particular aqara buttons peculiarity ruins intuitive and seamless writing of automation. IMHO, action-to-state reposting should be done on the Z2M side for this device.
Z2M could do this, but I disagree that it should... Z2M is simply a "messenger". easy enough to automate either way.
In general, i agree. But it already has some device-specific options (occupancy_timeout and *_precision), so maybe it's a good idea to add something like a key name mapping ability for such strange-developed devices into Z2M?
For WXKG12LM, hold(long press) only works as
trigger:
- platform: mqtt
topic: 'zigbee2mqtt/xxxxxxxxxx'
condition:
condition: template
value_template: '{{ "hold" == trigger.payload_json.action }}'
(Notice it's 'trigger.payload_json.action' not 'trigger.payload_json.click')
and for single and double click, bellow works too
trigger:
- platform: state
entity_id: sensor.xxxxxxxxxx_click
to: 'double'
but, for WXKG01LM, long press is
trigger:
- platform: state
entity_id: sensor.yyyyyyyyyy_click
to: 'long'
or with platform: mqtt,
value_template: '{{ "hold" == trigger.payload_json.click }}'
So, we have to trigger them differently. It would be better to include in the documentation that, 'platform: state' method won't work with 'hold' and 'shake' actions for WXKG12LM
I am not sure about the 'click' and 'action' difference. Especially, WXKG12LM's 'hold' and WXKG01LM's 'long' is essentially the same human operation, but one is defined as 'click' and the other 'action'.
Further more, switch status of all things defined as 'action' won'be displayed in HOMEASSISTANT GUI. If you shake or hold WXKG12LM, it will be displayed as blank. Single and double clicks are displayed though. Not sure how to fix that.
from zigbee-shepherd-converters/converters/fromZigbee.js
WXKG12LM_action_click_multistate: {
cid: 'genMultistateInput',
type: ['attReport', 'readRsp'],
convert: (model, msg, publish, options) => {
const value = msg.data.data['presentValue'];
const lookup = {
1: {click: 'single'}, // single click
2: {click: 'double'}, // double click
16: {action: 'hold'}, // hold for more than 400ms
17: {action: 'release'}, // release after hold for more than 400ms
18: {action: 'shake'}, // shake
};
'click' and 'action' are mixed in one device and at least in HOMEASSISTANT there should be some other way to integrate. Because the vaule_template only seeks 'value_json.click'
bellow is example manual configuration for WXKG12LM
sensor:
- platform: "mqtt"
state_topic: "zigbee2mqtt/<FRIENDLY_NAME>"
availability_topic: "zigbee2mqtt/bridge/state"
icon: "mdi:toggle-switch"
value_template: "{{ value_json.click }}"
expire_after: 1
I am guessing here, but I figure 'value_json.action' won't be displayed.
for WXKG01LM, long press publishes 'click:long' not 'action:long' (and not 'action:hold')
WXKG01LM_click: {
cid: 'genOnOff',
type: ['attReport', 'readRsp'],
convert: (model, msg, publish, options) => {
const deviceID = msg.endpoints[0].device.ieeeAddr;
const state = msg.data.data['onOff'];
if (!store[deviceID]) {
store[deviceID] = {};
}
// 0 = click down, 1 = click up, else = multiple clicks
if (state === 0) {
store[deviceID].timer = setTimeout(() => {
publish({click: 'long'});
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
For WXKG12LM, hold(long press) only works as
(Notice it's 'trigger.payload_json.action' not 'trigger.payload_json.click')
and for single and double click, bellow works too
but, for WXKG01LM, long press is
or with platform: mqtt,
So, we have to trigger them differently. It would be better to include in the documentation that, 'platform: state' method won't work with 'hold' and 'shake' actions for WXKG12LM
I am not sure about the 'click' and 'action' difference. Especially, WXKG12LM's 'hold' and WXKG01LM's 'long' is essentially the same human operation, but one is defined as 'click' and the other 'action'.
Further more, switch status of all things defined as 'action' won'be displayed in HOMEASSISTANT GUI. If you shake or hold WXKG12LM, it will be displayed as blank. Single and double clicks are displayed though. Not sure how to fix that.
from zigbee-shepherd-converters/converters/fromZigbee.js
'click' and 'action' are mixed in one device and at least in HOMEASSISTANT there should be some other way to integrate. Because the vaule_template only seeks 'value_json.click'
bellow is example manual configuration for WXKG12LM
I am guessing here, but I figure 'value_json.action' won't be displayed.
for WXKG01LM, long press publishes 'click:long' not 'action:long' (and not 'action:hold')