I use several HA’s on the same network and want to share the sensor / switch state between HA’s. I use MQTT statestream to stream the states of its sensors / switches to its MQTT broker. I put this automation below to allow other HA’s to use MQTT discovery which automatically create’s all the sensors for it’s use. It will populate all the sensors / switches config data on restart (and on every state change).
I changed the automation so it looks for the entities in the MQTT broker so I don’t have to specify. I also found it didn’t add all the entities at restart.
These automations will look at the MQTT Broker under the homeassistant topic that MQTT Statestream uses by default. It will create config payloads for binary_sensors, sensors, switches and lights so MQTT Discovery on another HA will populate these entities automatically. The last automation will allow control of the lights and switches from the other HA.
Hey, so I tried to make an automation to send sensor states too.
I have a dedicated Hass.io instance with a zigbee & zwave radio that then publishes via MQTT Statestream component to my Primary Hass.io running in a virtual machine.
I want to publish temperature sensors and any other sensors with a state. My automation works, but loses the device_class if specified. As a workaround, I’m using customize to put the device class back.
Thanks, I did the same. I think I’ll add units of measurement as well to the sensors as most my sensor have that attribute and I’ll use customizer if they don’t.
I added uniq_id to the config so that the mqtt entities show up in configuration/integration. In the automation below, I made sure all the sensors in rpi3 had a unit of measurement so the config will trigger and include that.
Thanks for this automation. I think I could use it to connect my inside HA to my outside HA. However I get an error I do not know how to fix. I’m trying to use my inside fibaro sensor connected to my alarm to turn off my outside lights. So if the alarm is set, turn off outside lights.
In the inside HA i I have a MQTT statestream working. (I see in MQTT fx that the binary sensor is published as either on or off in the topic homeassistant/binary_sensor/sensor_jablotro_sensor_2/state.
I then use your whole automation scripts in the outside HA and stating in the config of the outside HA. MQTT discovery. If I then swith alarm on or off I got an error in the outside HA:
2019-03-20 11:08:55 ERROR (MainThread) [homeassistant.components.mqtt.binary_sensor] Exception in async_discover when dispatching ‘mqtt_discovery_new_binary_sensor_mqtt’: ({‘device_class’: ‘’, ‘state_topic’: ‘homeassistant/binary_sensor/sensor_jablotro_sensor_2/state’, ‘payload_on’: ‘on’, ‘payload_off’: ‘off’, ‘platform’: ‘mqtt’, ‘name’: ‘Armed’},)
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/config_validation.py”, line 643, in call
return super().call(data)
File “/srv/homeassistant/lib/python3.5/site-packages/voluptuous/schema_builder.py”, line 267, in call
return self._compiled([], data)
File “/srv/homeassistant/lib/python3.5/site-packages/voluptuous/schema_builder.py”, line 589, in validate_dict
return base_validate(path, iteritems(data), out)
File “/srv/homeassistant/lib/python3.5/site-packages/voluptuous/schema_builder.py”, line 427, in validate_mapping
raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: value is not allowed for dictionary value @ data[‘device_class’]
If I search for this error I see a couple of recent threads so maybe it is a problem of a recent HASSIO version (using 0.89?) Anybody knows how to fix this?
I found out that I had to customize the sensor in the inside HA in the device class as “lock”. Then it was created in the outside HA! Only the icon of the lock is a bit strange in that if it is on I see an open lock…
Thanks for this, it’s what I’ve been looking for. I had a question about the integrations tab though. The sensors that I’m discovering are things like my cable modem state, software version, etc, so they don’t really have a device class or unit of measurement. All the sensors show up on the integrations tab in a box titled “Entities without devices”. Is there a way to divide them up by device?
You might try to define the class of the sensor (or binary sensor) through customization so that it will be defined in the integration.
Device Class
The way these sensors are displayed in the frontend can be modified in the customize section. The following device classes are supported for sensors:
None : Generic sensor. This is the default and doesn’t need to be set.
battery : Percentage of battery that is left.
humidity : Percentage of humidity in the air.
illuminance : The current light level in lx or lm.
signal_strength : Signal strength in dB or dBm.
temperature : Temperature in °C or °F.
power : Power in W or kW.
pressure : Pressure in hPa or mbar.
timestamp : Datetime object or timestamp string.
DEVICE CLASS
The way these sensors are displayed in the frontend can be modified in the customize section. The following device classes are supported for binary sensors:
None : Generic on/off. This is the default and doesn’t need to be set.
battery : On means low, Off means normal
cold : On means cold, Off means normal
connectivity : On means connected, Off means disconnected
door : On means open, Off means closed
garage_door : On means open, Off means closed
gas : On means gas detected, Off means no gas (clear)
heat : On means hot, Off means normal
light : On means light detected, Off means no light
lock : On means open (unlocked), Off means closed (locked)
moisture : On means moisture detected (wet), Off means no moisture (dry)
motion : On means motion detected, Off means no motion (clear)
moving : On means moving, Off means not moving (stopped)
occupancy : On means occupied, Off means not occupied (clear)
opening : On means open, Off means closed
plug : On means device is plugged in, Off means device is unplugged
power : On means power detected, Off means no power
presence : On means home, Off means away
problem : On means problem detected, Off means no problem (OK)
safety : On means unsafe, Off means safe
smoke : On means smoke detected, Off means no smoke (clear)
sound : On means sound detected, Off means no sound (clear)
vibration : On means vibration detected, Off means no vibration (clear)
Thanks. I’ve messed around with it and found various ways NOT to make it work For now I’m happy with them just coming over to my main instance.
I did find this for when you goober it up good and do things like advertise sensor.time, etc that you want to undo. There is a NodeJS app named MQTT-Forget:
But you need to tell it to forget both your homeassistant/ topic and your trigger topic, or else they just keep coming back.
I just realized that all my mqtt sensors / lights / switches that have auto config show up on the integration page saying they are without entities. I think this is wrong as all the entities have devices and device classes.
Thanks! I didn’t see this but after messing around for most of the day I figured it out. Exhausted but I’ll post my config at some point. Much appreciated for the starting guide though, was extremely helpful!
Just follow up here is my config for lights, switches, sensors, binary sensors, locks and covers. I realized this morning that transitions aren’t working so I’m going to have to modify my lights a bit to get them to work (looks like I’ll be going for the JSON format), but figured this might help someone else. The brightness control works just fine.
And these are the automations running on the slave instance (note I have the binary sensor turn off because it was spamming messages. I think I fixed that but I left the automation in as I don’t think it hurts):