Hello,
I am wondering if it is possible to use 2 integrations for same device. My use case is that I want to use MQTT to receive any device state changes and use other integration (API based) to control the device.
Thanks
Hello,
I am wondering if it is possible to use 2 integrations for same device. My use case is that I want to use MQTT to receive any device state changes and use other integration (API based) to control the device.
Thanks
What kind of device is it? A switch or sensor or lock or what exactly?
Is it a RESTful API or something else? In other words, how will you issue API commands from Home Assistant to the physical device?
Look at the template integrations. They should allow you to set sensor device vs actionable device for same entity
For example a light bulb (zigbee) which can be turned on/out outside home assistant as well.
In this case I want to sync the state of the light bulb in home assistant using mqtt and control that same lightbulb using an REST API (using custom integration ofcourse)
@ tmjpugh
Do you have an example or a yaml?
But if are already using MQTT to get the state in HA, why would you want to use REST rather than MQTT to set it?
To reduce latency and know if a command is succesful.
Some more details:
Using MQTT (in combination with for example zigbee2mqtt) for sending commands. The flow is following: HA → MQTT → Zigbee2MQTT → ZigbeeDevice. This means that there is some overhead (networking) and HA never can know if the Zigbee device has received the command (and accepted it) and therefor relies on optimistic behaviour. However sending a command through an zigbee gateway directly will cut out MQTT and as long as the gateway supports the confirmation protocol of zigbee, the HA integration can know if the device successfully received and processed the command, thus the reliability of controlling light bulbs is higher
Ok, so you want to use the REST api of your zigbee gateway, right?
I don’t see why it would be a problem.
I assume that Z2M will receive the updated state and forward it to MQTT. No different that if, e.g., a smart plug would be turned off/on through the builtin button.
For the record, note that you can disable the “optimistic” mode of z2m, so a lot of headaches and cumbersomeness for little return, imo (network latency for home appliances is negligible, here).
Yes in this case I want to use the REST API of the zigbee gateway for sending commands and use MQTT for state updates. However I am not sure how to connect these 2 things in home assistant, for example using a lightbulb.
Ps it is not only about latency (which ofcourse depends on your hardware and setup) but also about reliability when sending commands. The REST API provides means to know if a command is processed or not in a synchronised way.
You’ll have to use a light template, with MQTT for the state, and rest_command for the actions. I’m not sure you’ll able to alter the state based upon the return status of the REST call, though.
Is it documented that your gateway will wait for the ACK of the device before returning from the API call?
Hmm kind of requirement to alter the state of return status of the rest call. Perhaps I can use this doc as inspiration.
And yes the gateway will wait for the ACK of the device before returning from the API call