@francisp, thank you very much!!! this worked. I started looking into mqtt eventstream but for 3 sensors. it is overkill. I will use automtion to keep these updated between my master and slave instance…that was the main reason for doing this.
If your device isn’t programmed to send a “last will & testament” (availability topic) then how does it help you to force the availability to always be “online”? what happens if your device actually goes offline? How will you know if it’s actually online or offline if you have forced it online?
Very good point @finity…however, I am at a loss on how to implement this properly. Here is my scenario. I have a hass.io vm on my server that is my primary. It has a wyze hub (usb) and a bunch of sensors connect to it. I really like the wyze products. Now my garage is out of range for this hub. So I bought a second wyze hub and connected it to a raspberry pi hass.io instance that sits close to the garage for the further away sensors. This is my second or slave instance of hass.io. I have tried a few things so far but with very limited reliability. I tried the HACS Remote which keeps losing connectivity to the Slave instance. I have also tried connecting node red with a Slave instance as a second server but that also didn’t get the state change reliably. Hence I am now experimenting with the MQTT publish approach.
So in my current setup I have setup automations that sends the availability and state on every state change.
alias: Side Door (Garage) - Open
description: ''
trigger:
- entity_id: binary_sensor.wyze_garage_side_door
from: 'off'
platform: state
to: 'on'
condition: []
action:
- data:
payload: online
retain: true
topic: /remote/garagesidedoor/availability
service: mqtt.publish
- data:
payload: 'ON'
retain: true
topic: /remote/garagesidedoor
service: mqtt.publish
And in my Primary instance I have the corresponding MQTT Binary Sensors that are updated based on these automation in the Slave.
Now I did venture a bit in the MQTT Eventstream but couldn’t figure out how to connect the MQTT subscribed topic to the MQTT Binary Sensors I created in the Primary instance. If this is the right approach, would you be able to help me set it up?..I am constantly learning when I try to solve something with HA.
Everything you have tried has failed for the same reason: poor network connectivity. MQTT will suffer the same fate. Use of the availability topic isn’t going to improve anything (especially not the way you’re using it).
Statestream publishes the state information for each entity as the changes happen. you can also set it to update the attributes as well. It will publish all of that info to the broker to be available for other clients to consume. You can set up statestream to publish thew states of all entities or just a select few.
then in your main HA you will need to configure an MQTT binary sensor to react to changes in the MQTT message from the original sensor.
So in my case I used “hass” as the base topic. then the details of my switch are published to the topic “hass/switch/comp_room_light_sw/…” including all of the entity’s attributes.
In your case (if using the same base topic) the binary sensor would publish it’s state on the topic “hass/binary_sensor/your_device_id/state”
Then you would create an mqtt binary sensor in your “master” HA that listens for changes on that topic.: