MQTT works, but "Entity not available" in Lovelace

Hi all,

I had some problems with MQTT, but got it working with your pointers.

But now I have the following, I’m getting info from my smart meter and this info is send every 10 seconds. ONLY, when a sensor is not used in that 10 seconds (gas for instance), the sensor disappears from Hassio (checked “<>”) and Lovelace looks like this: https://imgur.com/Wz49N9t

Is there a way to maintain the last value from the sensor, because now it doesn’t look that nice…

You need to disable sending LWT messages. What are you using to publish the mqtt messages?

I use mqtt_eventstream, don’t know how/where to disable…?

Set in MASTER HASSIO:

mqtt:
broker: 192.168.1.111
port: 1883
client_id: hassiomaster
keepalive: 60

mqtt_eventstream:
subscribe_topic: slavetopic

Set in SLAVE HASSIO:

mqtt:
broker: 192.168.1.111
port: 1883
client_id: hassioslave
keepalive: 60

mqtt_eventstream:
publish_topic: slavetopic

Maybe define a blank will message?

I was more thinking of changing to statestream instead of eventstream.

As I think it goes:

  • Smart Meter sends out values every 10 seconds. If a value does not change, it is send anyway.
  • Eventstream: No change in value, so not sending state of that sensor
  • Statestream: No change in value, but timestamp is changed, so sending state of that sensor?

Is this correct?

did you ever sort this out, this must be a common problem surely?
I have the same issue too, neither eventstream or statestream seemed to resolve it

I have got it working, but am now on holiday. Can you remind me next week, then I can see what I’ve done.

1 Like

@Eltjo_de_Waard are you home yet, all refreshed and ready to fix my problems?! :wink:

Hi! Yes, back from holiday!

I will tell you what I’ve got. Don’t know if it is correct or maybe “over done”, but it work so I don’t want to mess with it :slight_smile: (Or someone here can tell that something is not necessary).

Ok, so I have two RPI, one is my Master and the other is just for sending data from my smart meter (Gas and electricity incl. solar numbers).

On MASTER:

  1. Installed add-on “Mosquitto broker” with this config:

{
“logins”: [],
“anonymous”: true,
“customize”: {
“active”: false,
“folder”: “mosquitto”
},
“certfile”: “fullchain.pem”,
“keyfile”: “privkey.pem”
}

  1. Install “Integration” “MQTT: Mosquitto Broker” (And here I don’t know if this is correct or that this is double). Can’t see what I’ve written down but I think I gave an username and password here.

  2. In configuration.yaml
    mqtt_eventstream:
    subscribe_topic: slavetopic

  3. In configuration.yaml

  • platform: mqtt
    state_topic: ‘ha/gas_totaal_variabel’
    name: ‘totaal_gasverbruik_variabel’
    unit_of_measurement: ‘m3’
    value_template: ‘{{ value_json.day_1 }}’

On SLAVE

  1. In configuration.yaml
    mqtt_eventstream:
    publish_topic: slavetopic

  2. In automation.yaml (one example, but this is for every sensor value I want)

  • action:
    • service: mqtt.publish
      data_template:
      topic: ‘ha/gas_totaal_variabel’
      retain: true
      payload: ‘{“day_1”:"{{ (states.sensor.gas_consumption.state | float) | max (0) | round(3) }}"}’
      alias: ‘Gas waarde totaal variabel’
      trigger:
      platform: state
      entity_id: sensor.gas_consumption

And that’s it! Basically what happens (I think) is that when a value in SLAVE is changed the automation will make sure it is send through MQTT. And in MASTER it is said they want to use this sensor reading (point 4)

Hope this helps, otherwise give me another message.

(And will you let me know if it helped you?)

Kind regards,
Eltjo

1 Like

Hey @Eltjo_de_Waard massive thankyou for taking the time to write such a detailed reply.
I was hoping that eventstream would work without having to define every sensor in the configuration.yaml and write automations to post the sensor updates (as it currently sort of does, but then the sensors keep disappearing!) - so I think your solution is probably the only way to get this working properly.
Thankyou for this, I will give this a try and report back!

Have a look at this strategy:

It uses the combination of MQTT Statestream to exchange entity states, between server/client (master/slave) instances of Home Assistant plus MQTT Discovery to automatically create the entities on the client (slave) instance of Home Assistant.

There’s also a custom component called home-assistant-remote . It uses Websockets instead of MQTT to create a bi-directional connection between two instances of Home Assistant.

1 Like

Thankyou too @123 ! I shall try this in the first instance, and see if it does the job. I do need to be able to turn the slave switches on and off from the master instance, so this could be ideal.
Such a great help on these forums, cheers!

I failed! I couldn’t get home assistant remote to do anything, and with the other mqtt method, the automations that guy used created tens of copies of each of my sensors and ground both master and slave to a halt. I really wish it weren’t so tricky to link 2 instances of HA - i heard there was a method using node-red but I can’t find it.