Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying a unified description for message topics #1393

Closed
MarcSchmidt opened this issue Jul 13, 2020 · 16 comments
Closed

Applying a unified description for message topics #1393

MarcSchmidt opened this issue Jul 13, 2020 · 16 comments

Comments

@MarcSchmidt
Copy link
Contributor

Hello,

Currently, I need to consider different topics (like "action" and "click") when I am switching between remotes/switches, while these remotes do similar things. It would be preferable when all remotes/switches would use a unified topic e.g. all use "action" or all use "click".
Example:
Xiaomi WXKG02LM
Payload: {"battery":100,"voltage":3012,"linkquality":65,"click":"single"}
Philips 324131092621
Payload: {"battery":100,"linkquality":68,"counter":1,"brightness":255,"update_available":false,"action":"on-press","duration":0}
IKEA E1524/E1810
{"battery":34,"linkquality":55,"update_available":false,"action":"toggle"}

Personally I would suggest the usage of the term "action" as it is more versatile.

From my understanding the required change would be to replace all "click" with "action" in the converter fromZigbee.js.
Example
Xiaomi WXKG02LM
WXKG02LM_click: {
cluster: 'genOnOff',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
return {click: getKey(model.endpoint(msg.device), msg.endpoint.ID)};
},
},
IKEA E1524/E1810
E1524_E1810_toggle: {
cluster: 'genOnOff',
type: 'commandToggle',
convert: (model, msg, publish, options, meta) => {
const payload = {action: getProperty('toggle', msg, model)};
return payload;
},
},

So my question would be:

  1. Can we unify the structure for all devices?
  2. Is my understanding of the code correct, that it would only require an update of one file?

Greetings
Marc

@dchwilk
Copy link

dchwilk commented Jul 13, 2020

that would be really helpful

@Koenkk
Copy link
Owner

Koenkk commented Jul 14, 2020

click is deprecated and should be replaced by action, all new integrations are forced to use action, as changing click to action would result in a breaking change this is currently not done (until Zigbee2mqtt 2.0.0).

Something we can consider is adding both for the time being, however I'm not sure if this will create confusion for users.

@MarcSchmidt
Copy link
Contributor Author

Thx for the fast reply.
I think for a smooth transition from the deprecated solution to the newer action a duplication should be considered. Then the users could switch over time from one solution to the newer one and are not forced to make a hard migration to 2.0.

To prevent the confusion of users the documentation could be updated with an deprecation information. (This would also prevent creating more technical debt until the new version is out)

@Koenkk
Copy link
Owner

Koenkk commented Jul 14, 2020

Good, in case you are interested feel free to make some PRs already (simply add action e.g. here:

return {click: getKey(model.endpoint(msg.device), msg.endpoint.ID)};
). If not I will pick this up later.

@MarcSchmidt
Copy link
Contributor Author

I have started with the first device and will create more PRs later on.

@MarcSchmidt
Copy link
Contributor Author

@Koenkk Is there any device, for which click is not deprecated in favor of action? Or can I update all devices in the list

@Koenkk
Copy link
Owner

Koenkk commented Jul 24, 2020

Closing this as #1399 is merged

@uncle-fed
Copy link
Contributor

Something we can consider is adding both for the time being, however I'm not sure if this will create confusion for users.

Speaking of user's confusion...

Was this intentional that the legacy value for a left/right switch looks like "click":"right_double" but the new one looks like "action":"double_right" (i.e., the value has the order of right and double reversed).

Confused my existing automation for sure :-)

@uncle-fed
Copy link
Contributor

@Koenkk , what about consistency when the 'legacy: false' is set?
I am getting this now for 2 different devices...
Don't you think that the double part should go the end of the value, rather?

WXCJKG12LM - Xiaomi Aqara Opple switch 2 bands:           payload '{"action":"button_3_single"}'
WXKG02LM - Xiaomi Aqara double key wireless wall switch:  payload '{"action":"double_right"}'

@Koenkk
Copy link
Owner

Koenkk commented Aug 17, 2020

double_right is the correct one, only the devices that used click have been refactored, devices that already used action have not been refactored yet (therefore legacy: false won't make a difference).

@uncle-fed
Copy link
Contributor

Not to question it largely, just curious, what sort of logic led to decision to have <typeOfAction>_<subDeviceId> order?
Is there more to it or was it a random decision?

@Koenkk
Copy link
Owner

Koenkk commented Aug 17, 2020

For device with only a single endpoint (e.g. WXKG01LM) the payload will be double, in my opinion it is logic that for the devices with multiple endpoints the endpoint was added as a postfix.

@AlexeyHimki
Copy link

zigbee2mqtt 1.14.3
Xiaomi QBKG11LM in Decoupled mode
When I press the button physicaly:
{"state":"OFF","linkquality":63,"power":0,"consumption":0.98,"temperature":28,"action":"single"}
And when I toggle from HA:
{"state":"ON","linkquality":63,"power":0,"consumption":0.98,"temperature":28,"action":"single"}
There is the same action SINGLE. But I need a trigger that must be work only on a physical press.

How can I do this?

@Koenkk
Copy link
Owner

Koenkk commented Aug 18, 2020

@AlexeyHimki can you provide the debug logging of this?

To enable debug logging set in configuration.yaml:

advanced:
  log_level: debug

@AlexeyHimki
Copy link

AlexeyHimki commented Aug 18, 2020

Physical press:

Zigbee2MQTT:debug 2020-08-19 00:46:13: Received Zigbee message from 'garderob.wired_switch', type 'attributeReport', cluster 'genMultistateInput', data '{"presentValue":1}' from endpoint 5 with groupID 0
Zigbee2MQTT:info  2020-08-19 00:46:13: MQTT publish: topic 'zigbee2mqtt/garderob.wired_switch', payload '{"state":"OFF","linkquality":39,"power":0,"consumption":0.98,"temperature":28,"action":"single"}'
Zigbee2MQTT:info  2020-08-19 00:46:13: MQTT publish: topic 'zigbee2mqtt/garderob.wired_switch', payload '{"state":"OFF","linkquality":39,"power":0,"consumption":0.98,"temperature":28,"action":""}'
Zigbee2MQTT:info  2020-08-19 00:46:13: MQTT publish: topic 'homeassistant/device_automation/0x00158d00041e7383/action_single/config', payload '{"automation_type":"trigger","type":"action","subtype":"single","payload":"single","topic":"zigbee2mqtt/garderob.wired_switch/action","device":{"identifiers":["zigbee2mqtt_0x00158d00041e7383"],"name":"garderob.wired_switch","sw_version":"Zigbee2MQTT 1.14.3","model":"Aqara single key wired wall switch (QBKG11LM)","manufacturer":"Xiaomi"}}'
Zigbee2MQTT:info  2020-08-19 00:46:13: MQTT publish: topic 'zigbee2mqtt/garderob.wired_switch/action', payload 'single'

Remote toggle:

Zigbee2MQTT:debug 2020-08-19 00:48:13: Received MQTT message on 'zigbee2mqtt/garderob.wired_switch/set' with data 'ON'
Zigbee2MQTT:debug 2020-08-19 00:48:13: Publishing 'set' 'state' to 'garderob.wired_switch'
Zigbee2MQTT:info  2020-08-19 00:48:13: MQTT publish: topic 'zigbee2mqtt/garderob.wired_switch', payload '{"state":"ON","linkquality":39,"power":0,"consumption":0.98,"temperature":28}'
Zigbee2MQTT:debug 2020-08-19 00:48:13: Received Zigbee message from 'garderob.wired_switch', type 'attributeReport', cluster 'genOnOff', data '{"61440":117440516,"onOff":1}' from endpoint 1 with groupID 0
Zigbee2MQTT:info  2020-08-19 00:48:13: MQTT publish: topic 'zigbee2mqtt/garderob.wired_switch', payload '{"state":"ON","linkquality":55,"power":0,"consumption":0.98,"temperature":28,"action":"single"}'
Zigbee2MQTT:info  2020-08-19 00:48:13: MQTT publish: topic 'zigbee2mqtt/garderob.wired_switch', payload '{"state":"ON","linkquality":55,"power":0,"consumption":0.98,"temperature":28,"action":""}'
Zigbee2MQTT:info  2020-08-19 00:48:13: MQTT publish: topic 'zigbee2mqtt/garderob.wired_switch/action', payload 'single'

@Koenkk
Copy link
Owner

Koenkk commented Aug 19, 2020

@AlexeyHimki should be fixed

Changes will be available in the latest dev branch in a few hours (https://www.zigbee2mqtt.io/how_tos/how-to-switch-to-dev-branch.html)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants