Here is the instructions, you will need one automation on one of the HA’s, and statestream on the sensor HA and discovery setup the main HA.
###in main HA####
mqtt:
broker: 192.168.2.12
client_id: 3333
discovery: true
discovery_prefix: rpi1
###in sensor HA ##
mqtt:
broker: 192.168.2.12
client_id: 4444
mqtt_statestream:
base_topic: rpi1
publish_attributes: true
publish_timestamps: true
include:
domains:
- sensor
###in either HA###
#########################################################################################
#########################################################################################
automation mqtt_config_entity_creator_sensor:
alias: mqtt_config_entity_creator_sensor
trigger:
- platform: mqtt
topic: 'rpi1/sensor/#'
condition:
condition: template
value_template: "{{ trigger.topic.split('/')[3] == 'state' }}"
action:
- service: mqtt.publish
data_template:
topic: "homeassistant/{{ trigger.topic.split('/')[1] }}/{{ trigger.topic.split('/')[2] }}/config"
# payload: ""
payload: "{\"name\": \"{{ trigger.topic.split('/')[2]| replace('_', ' ') | title }}\",\"state_topic\": \"rpi3/{{ trigger.topic.split('/')[1] }}/{{ trigger.topic.split('/')[2] }}/state\" }"
retain: true
#########################################################################################
#########################################################################################