OpenZWave / Zwave2Mqtt

Fully configurable Zwave to MQTT gateway and Control Panel using NodeJS and Vue
MIT License
356 stars 93 forks source link

[Feature] Home Assistant integration #27

Closed MarsWarrior closed 5 years ago

MarsWarrior commented 5 years ago

I see in your todo list that integration (discovery I assume) with home assistant is planned.

Can you tell me when you think to build this functionality?

I am already using zigbee2mqtt, so a big fan of mqtt and would be very happy if full integration with the device registry of home assistant is implemented for z-wave!

robertsLando commented 5 years ago

I have no time to implement it right now, If you want to submit a PR I can review it.

My idea is to start from zigbee2mqtt homeassistant gateway and customize it for zwave, the homeassistan gateway will work like the normal one and will subscribe to mqtt and zwave events like:

    mqtt.on('writeRequest', onWriteRequest.bind(this))
    mqtt.on('broadcastRequest', onBroadRequest.bind(this))
    mqtt.on('apiCall', onApiRequest.bind(this))

    zwave.on('valueChanged', onValueChanged.bind(this))
    zwave.on('nodeStatus', onNodeStatus.bind(this))
    zwave.on('scanComplete', onScanComplete.bind(this))
frankhommers commented 5 years ago

I would love this too!

robertsLando commented 5 years ago

I'm releasing a first beta version of hass integration today, any beta tester available here?

jshridha commented 5 years ago

I'd be happy to try out the Hass integration

robertsLando commented 5 years ago

@jshridha Check last commit

Fishwaldo commented 5 years ago

Just a random question (maybe more appropriate for the HASS guys, idk much about mqtt and this auto discovery). Say I have a multifunction device, like a combined temp/light/movement/humidity sensor - Does that mean that hass must also have exactly the same device type to support all those features on my device? When I look at the "sensors" entry on the hass website, seems it only supports a "single" sensor type?

MarsWarrior commented 5 years ago

Just a random question (maybe more appropriate for the HASS guys, idk much about mqtt and this auto discovery). Say I have a multifunction device, like a combined temp/light/movement/humidity sensor - Does that mean that hass must also have exactly the same device type to support all those features on my device? When I look at the "sensors" entry on the hass website, seems it only supports a "single" sensor type?

In your case you get - depending on how the discovery by zwave2mqtt is done - a temp, light, movement and humidity sensor, all from the same device!

image

Fishwaldo commented 5 years ago

Ok. Good to know. Then how about a bit more of a convoluted example.

A Wall Switch with a Power Meter? (Eg, W, amps, voltage, Kw/h etc)

So it’s a “switch and a sensor”?

robertsLando commented 5 years ago

Yes Justin... I’m working to support thermostats (climate) and fans too on Zwave2mqtt, maybe this evening or next week there will be a first working version

Daniel

On 12 Jul 2019, at 12:09, Justin Hammond notifications@github.com wrote:

Ok. Good to know. Then how about a bit more of a convoluted example.

A Wall Switch with a Power Meter? (Eg, W, amps, voltage, Kw/h etc)

So it’s a “switch and a sensor”?

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub, or mute the thread.

robertsLando commented 5 years ago

@MarsWarrior Could you do some tests with the latest version from master ?

jshridha commented 5 years ago

@robertsLando I'm not seeing any of the devices show up in home assistant yet. I'm monitoring the mqtt traffic and it looks like it is only publishing the changes under the specified prefix topic and it appears it's not publishing under the prefix topic with the correct format for hass discovery. Below is my configuration and mqtt traffic seen.

Can you let me know if my configuration is correct?

image

image

image

robertsLando commented 5 years ago

Could you check if there is any error in console log? Are you using latest version from master? Please set the payload type to json time value or entire zeave object in configuration. Also what kind of zwave device do you have in your network?

Daniel

On 14 Jul 2019, at 20:57, Jay notifications@github.com wrote:

@robertsLando I'm not seeing any of the devices show up in home assistant yet. I'm monitoring the mqtt traffic and it looks like it is only publishing the changes under the specified prefix topic and it appears it's not publishing under the prefix topic with the correct format for hass discovery. Below is my configuration and mqtt traffic seen.

Can you let me know if my configuration is correct?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

jshridha commented 5 years ago

I did not see any errors in the console. I am using the latest commit. I built the docker image from scratch changing the hash to match the latest commit. I am using GE switches, GE/Jasco light dimmers, and first alert CO/smoke detectors.

I changed to json time value and entire zwave object, but I I'm still not seeing the hass-formatted messages.

robertsLando commented 5 years ago

Are you sure you don’t see anything publishing in /+/+/+/config? That’s the topic used for discovered devices and the ‘+’ are component type, node name, object id. could you tell me the type of devices you have in your network?

Daniel

On 15 Jul 2019, at 05:18, Jay notifications@github.com wrote:

I did not see any errors in the console. I am using the latest commit. I built the docker image from scratch changing the hash to match the latest commit. I am using GE switches, GE/Jasco light dimmers, and first alert CO/smoke detectors.

I changed to json time value and entire zwave object, but I I'm still not seeing the hass-formatted messages.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

robertsLando commented 5 years ago

@jshridha I have found a wrong loop that caused disovery to break. Could you check it now with latest commit please?

jshridha commented 5 years ago

@robertsLando It's looking better. It looks like the sensors are being sent to the right topic. However, the light dimmers and fans are being shown up under the "cover" category instead of "light" and "fan" (see image below).

I have not yet tested if sending commands works correctly or if they show up in the hass interface correctly. I've only been monitoring the traffic so far.

As an additional feature, would be be possible to specify an alternative topic that homeassistant commands be sent to? Currently all updates (Zwave2Mqtt formatted and hass formatted) are going to the same topic. This will put additional load on the hass server since it's parsing messages it does not need to parse.

awulf commented 5 years ago

I've tried running it (commit 042cace4d39c7e7477c26cb79fcadff45af9dbee) but when I enable Hass Discovery it crashes for me

Error.txt

robertsLando commented 5 years ago

@awulf Try now, it was a typo :)

robertsLando commented 5 years ago

@jshridha Unfortunally I haven't any light dimmer or fans to test but I will try to make some changes in code. Could you send me there an example discovery payload for a dimmer and a fan to take inspiration?

Really thanks

jshridha commented 5 years ago

@robertsLando I don't have a payload for fans, but this is an example from a zigbee light switch that was sent by zigbee2mqtt:

topic: homeassistant/light/0x90fd9ffffe0d2bfe/light/config

{
  "brightness": true,
  "color_temp": true,
  "schema": "json",
  "command_topic": "zigbee2mqtt/Master Bedroom Lamp - Jay/set",
  "state_topic": "zigbee2mqtt/Master Bedroom Lamp - Jay",
  "name": "Master Bedroom Lamp - Jay_light",
  "unique_id": "0x90fd9ffffe0d2bfe_light_zigbee2mqtt",
  "device": {
    "identifiers": "zigbee2mqtt_0x90fd9ffffe0d2bfe",
    "name": "Master Bedroom Lamp - Jay",
    "sw_version": "Zigbee2mqtt 1.4.0",
    "model": "TRADFRI LED bulb E26/E27 980 lumen, dimmable, white spectrum, opal white (LED1545G12)",
    "manufacturer": "IKEA"
  },
  "availability_topic": "zigbee2mqtt/bridge/state"
}
robertsLando commented 5 years ago

@jshridha Check with latest commit e0662f74a959a16cfc4c58982293c2888102674a

robertsLando commented 5 years ago

@jshridha could you also join the slack chat? There we can chat faster https://join.slack.com/t/zwave2mqtt/shared_invite/enQtNjc4NjgyNjc3NDI2LTc3OGQzYmJlZDIzZTJhMzUzZWQ3M2Q3NThmMjY5MGY1MTc4NjFiOWZhZWE5YjNmNGE0OWRjZjJiMjliZGQyYmU

MarsWarrior commented 5 years ago

@MarsWarrior Could you do some tests with the latest version from master ?

As soon as my z-wave stick functions again I will join testing. Currently no z-wave network anymore 😢

My z-wave network consists of only 230V power switching and power measuring nodes btw. All other stuff is WiFi and Zigbee (lights, switches, temp/humi sensors).

robertsLando commented 5 years ago

@MarsWarrior No worries thanks anyway :) If you want to join the slack channel you are welcome

awulf commented 5 years ago

Thanks @robertsLando I got it running now, but looks like the discovery topics are being sent to the prefix set for zwave2mqtt, rather than the homeassistant prefix.

Screen Shot 2019-07-16 at 9 34 42 pm

robertsLando commented 5 years ago

@awulf The prefix used is the one specified in mqtt settings :) Change that one or the one in hass configutration to be the same

jshridha commented 5 years ago

@robertsLando It would be great if that was a user-customizable topic. That way hass isn't parsing unnecessary topics (e.g. "Study", "Theatre", "Living Room", etc from @awulf 's example above)

awulf commented 5 years ago

Yeah would be good if the prefix for discovery is user customisable (and defaulting to 'homeassistant'). As you can see on the screenshot the other subscribers (such as zigbee2mqtt) do it this way.

awulf commented 5 years ago

I found a bug where often the "Device HASS JSON" would be a mixture of the device you select and the last device in my list of devices. E.g. selecting the Garage Door switch shows the Bedroom 2 light switch (image attached). The discovery JSON in MQTT explorer is showing up correctly. I have been trying to change the JSON for the Garage Door from "switch" to "cover" but haven't been able to save it. No errors in the logs.

Screen Shot 2019-07-16 at 11 52 59 pm

robertsLando commented 5 years ago

I'm releasing a patch version 2.0.1 with a little fix

robertsLando commented 5 years ago

So will add a feature for discovery prefix too

robertsLando commented 5 years ago

@jshridha @awulf Available in 2.0.1

danjenkins commented 5 years ago

Excited to try this out in the coming weeks! I can't wait until Home Assistant isn't dealing with Z-Wave anymore and a) I can move it onto another server and b) move z-wave to something that'll never get restarted and it'll hopefully keep the z-wave network rock solid! Thanks @robertsLando !

awulf commented 5 years ago

Just had another go at using it, when trying to modify the Hass Device JSON, no matter what I put in (not even changing it) it will go red, shake and say JSON test failed Happens on both one 2.0.1 and the latest master.

I'm trying to get the garage door to become a cover rather than a switch. Home Assistant's built in Z-wave sees it as that, but Zwave2mqtt doesn't.

jshridha commented 5 years ago

@awulf You can ignore the red JSON test failed. What is happening is after you hit the "update" button, the text box is cleared out. Since it's clear now, the input is no longer valid. After you click on the hass device again, you'll see the updated JSON and then you can click on "rediscover" to send the MQTT discovery message.

awulf commented 5 years ago

Have tried that, and it does temporarily work. But when I reboot zwave2mqtt it goes back to the default.

jshridha commented 5 years ago

Yes that's right. I think ti's meant to be a troubleshooting/discovery tool. It's not persistent.

robertsLando commented 5 years ago

@awulf to make it persistent you need to press "STORE" button at the top of hass devices table

joselito11 commented 5 years ago

I have made a simple tutorial to try out ZWAVE2MQTT add-on in Home Assistant:

  1. Add MQTT to Home Assistant I installed add-on Mosquito broker and added mqtt: https://www.home-assistant.io/components/mqtt/ with discovery: true https://www.home-assistant.io/docs/mqtt/discovery/ to configuration.yaml

    mqtt:
    broker: core-mosquitto
    username: !secret mqtt_username
    password: !secret mqtt_password
    discovery: true
  2. Install ZWAVE2MQTT add-on, (Optional: open port to 8091 or change to your needs)

  3. Delete Zwave integration and remove zwave:config from configuration.yaml (for quick test, you can just stop zwave network in zwave panel, but this is not recommended, because cause problems after HA restart)

  4. Start ZWAVE2MQTT, open web ui, and setup the add-on

  5. In Zwave settings setup Serial Port (Mine is /dev/ttyACM0, same as for Zwave integration. Setup Poll Interval (Mine is 60000 millis, dont know if is correct for 15 nodes).

  6. In MQTT settings setup Name (zwave), Host url- mqtt broker address (my_domain.duckdns.org), Port (mqtt port, mine is 1883), Reconnect peroid (mine is 60000, think it will do), Prefix (default is homeassistant to be discovered), enable Retain and Auth, and add there your mqtt username and password.

  7. In Gateway settings setup Type (ValueID topic) and Payload (Entire Z-wave value Object) and enable Hass Discovery.

  8. Go to Control Panel and the controller with powered nodes should appear, for battery nodes must wait to be wake up or wake them.

  9. The zwave nodes are now in mqtt integration and have new entity names in Home Assistant. Motion sensors are created as _contact sensor with open/closed. In Home Assistant they are as door sensor. So you must customize device in customize.yaml:

    binary_sensor.*_contact:
    icon: mdi:walk
    device_class: motion

(10.) If you want go back to Zwave integration, stop ZWAVE2MQTT add-on, start zwave network or enable back zwave integration and restart Home Assistant. Everything should be back again.

(11.) If you decide to stay, replace old entities with new entities in your setup(sensors, automations,…). You can also rename new entities with names from old zwave integration.

Please add your opinions, correcture,…

johntdyer commented 5 years ago

@joselito11 - Tried this but the UI doesn’t seem to accept the toggles when I change them.

Here is an example showing it changing back every time I change the state

https://www.dropbox.com/s/lo2h6fo80fjloib/RPReplay_Final1564143522.MP4?dl=0

ahknight commented 5 years ago

I had the same issue (the delayed toggle). What happened to me was that OZW was still starting up (it can take 10 minutes for me) and it was queueing up messages, but the state on MQTT was synced back to the last-known state for the device even while the change appeared to be queued to send. If I waited a little while, it would get sent. If I got impatient then I got some rubber-banding on the toggle (off-on-off-on-off-on etc.).

ahknight commented 5 years ago

A different issue than the above: my motion sensors (binary) get imported as contact/door sensors instead of motion/motion. Easy to fix in HASS, but also a PITA when you have a lot of them.

Similarly, a voltage sensor came in as air volume or something similarly odd.

robertsLando commented 5 years ago

@ahknight YOu can fix this easily by set the correct device class in gateway values table.

@joselito11 Thanks for the tutorial. I'm closing this issue as now it is supported. Open new issue for device specific problems