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

Improved devicePublish topic parsing #1373

Merged
merged 5 commits into from
Apr 7, 2019
Merged

Conversation

Zagitta
Copy link
Sponsor Contributor

@Zagitta Zagitta commented Apr 4, 2019

I have refactored the devicePublish topic parsing to use regex capture groups as this seems more natural than manually splitting on slashes.
Furthermore I have added the ability to set attributes directly using the mqtt topic rather than having to set it using JSON while still maintaining backwards compatibility with the JSON approach.
This was mainly done to enable thermostat integration with homeassistant's MQTT climate component: https://www.home-assistant.io/components/climate.mqtt/ which does not support templating for the command topics to set the target temperature or mode.
In my case I have an eCozy thermostat named zigbee2mqtt/livingroom/thermostat_right which means I can now publish to the following topic to set the target temperature: zigbee2mqtt/livingroom/thermostat_right/set/occupied_heating_setpoint.

As such I can now control it from homeassitant with the following yaml:

- platform: mqtt
  name: Living room right
  min_temp: 7
  max_temp: 30
  availability_topic: "zigbee2mqtt/bridge/state"
  modes: ["off", "auto", "heat"]
  mode_command_topic: "zigbee2mqtt/livingroom/thermostat_right/set/system_mode"
  mode_state_topic: "zigbee2mqtt/livingroom/thermostat_right"
  mode_state_template: "{{ value_json.system_mode }}"
  current_temperature_topic: "zigbee2mqtt/livingroom/thermostat_right"
  current_temperature_template: "{{ value_json.local_temperature }}"
  temperature_command_topic: "zigbee2mqtt/livingroom/thermostat_right/set/occupied_heating_setpoint"
  temperature_state_topic: "zigbee2mqtt/livingroom/thermostat_right"
  temperature_state_template: "{{ value_json.occupied_heating_setpoint }}"

Next step is to add climate device discovery but that'll be later in a different PR.

@Koenkk
Copy link
Owner

Koenkk commented Apr 7, 2019

This is awesome! Could you perhaps update https://github.com/Koenkk/zigbee2mqtt/blob/dev/lib/extension/homeassistant.js with the thermostat auto discover configuration?

@Koenkk Koenkk merged commit 2554cf8 into Koenkk:dev Apr 7, 2019
Koenkk added a commit to Koenkk/zigbee2mqtt.io that referenced this pull request Apr 7, 2019
wilmardo pushed a commit to wilmardo/zigbee2mqtt that referenced this pull request Sep 26, 2019
* Refactored device publish parsing and added ability to set attributes directly

* Fixed topic subscriptions and null json object

* Fixed tests

* Added more testing of attribute

* Fixed linting issue.
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

Successfully merging this pull request may close these issues.

2 participants