Enviro+Air Mqtt-all.py - connects to broker, but data is not shown in HomeAssistant

Hi All,

This one has got me stumped. I’ve got an Enviro+Air with attached PMS5003 sensor and I’m running the Mqtt-all.py script to push data into Mosquitto broker running on Home Assistant.

If I manually run the Mqtt-all.py script on the pi

python3 /home/pi/Pimoroni/enviroplus/mqtt-all.py --broker 192.168.1.89 --topic enviroplus --interval 5

then it reports that it has connected to the broker OK and shows that it’s throwing out data

mqtt-all.py - Reads Enviro plus data and sends over mqtt.

    broker: 192.168.1.89
    client_id: raspi-00000000b1b6694d
    port: 1883
    topic: enviroplus

    Press Ctrl+C to exit!

    
PMS5003 sensor is connected
RPi serial: 00000000b1b6694d
Wi-Fi: connected

MQTT broker IP: 192.168.1.89
connected OK
{'temperature': 14, 'pressure': 70270, 'humidity': 85, 'oxidised': 1063, 'reduced': 6788, 'nh3': 4682, 'lux': 4, 'pm1': 9, 'pm25': 13, 'pm10': 13, 'serial': '00000000b1b6694d'}
mid: 1

Likewise, the Mosquitto Broker log on Home assistant shows that

1610248934: New connection from 192.168.1.100 on port 1883.
1610248934: New client connected from 192.168.1.100 as raspi-00000000b1b6694d (p2, c1, k60).

I’ve set “anonymous: true” in the Mosquitto broker config, and followed the mosquito broker documentation to create an ACL to allow anonymous “topic readwrite #” as well as “topic readwrite enviroplus”

I’m running version 5.1 of Mosquitto Broker on top of HomeAssistant OS

I created sensors in my config.yaml for the enviroplus sensors as below in the sensor: section, and HA says my config is valid.
- platform: mqtt
state_topic: “enviroplus”
value_template: “{{ value_json.pm1 }}”
name: “enviro_pm1”
unit_of_measurement: ‘pm’
icon: “mdi:thought-bubble-outline”
- platform: mqtt
state_topic: “enviroplus”
value_template: “{{ value_json.pm10 }}”
name: “enviro_pm10”
unit_of_measurement: ‘pm’
icon: “mdi:thought-bubble-outline”
- platform: mqtt
state_topic: “enviroplus”
value_template: “{{ value_json.pm25 }}”
name: “enviro_pm2”
unit_of_measurement: ‘pm’
icon: “mdi:thought-bubble”
- platform: mqtt
state_topic: “enviroplus”
value_template: “{{ value_json.humidity }}”
name: “enviro_humidity”
unit_of_measurement: ‘%’
icon: “mdi:water-percent”
- platform: mqtt
state_topic: “enviroplus”
value_template: “{{ value_json.pressure }}”
name: “enviro_pressure”
unit_of_measurement: ‘Pa’
icon: “mdi:arrow-down-bold”
- platform: mqtt
state_topic: “enviroplus”
value_template: “{{ value_json.temperature }}”
name: “enviro_temperature”
unit_of_measurement: ‘C’
icon: “mdi:thermometer”
- platform: mqtt
state_topic: “enviroplus”
value_template: “{{ value_json.lux }}”
name: “enviro_lux”
unit_of_measurement: ‘lx’
icon: “mdi:weather-sunny”
- platform: mqtt
state_topic: “enviroplus”
value_template: “{{ value_json.nh3 }}”
name: “enviro_nh3”
unit_of_measurement: ‘nh3’
icon: “mdi:thought-bubble”
- platform: mqtt
state_topic: “enviroplus”
value_template: “{{ value_json.reduced }}”
name: “enviro_reduced”
unit_of_measurement: ‘CO’
icon: “mdi:thought-bubble”
- platform: mqtt
state_topic: “enviroplus”
value_template: “{{ value_json.oxidised }}”
name: "enviro_oxidised "
unit_of_measurement: ‘no2’
icon: “mdi:thought-bubble”

Restarted HA, and added those new sensors to a card in my HA dashboard, but they all just show a status of “Unknown” and never update

So, the Pi says it’s connected to Mosquitto Broker, Mosquitto Broker say’s the Pi is connected, but if I start listening to “enviroplus” via the MQTT integration, I never get any data messages shown; and if I likewise listen to # in the MQTT broker, I see the messages from my zwave kit, but never see any “enviroplus” MQTT data.

Anyone got any ideas?

Installed MQTTExplorer on my computer and connected to the MQTT Broker on the Home Assistant, and I can see the enviroplus data there, and see it updating.

So I guess the problem must be with my sensor configs.

Still weird that telling the MQTT Integration in HA to listen to enviroplus returns no data.

Looks like this is a home assistant issue rather than an Enviro+ issue, because MQTT Explorer is showing that the MQTT broker IS receiving data from the Pi.

After much head scratching I stumbled across someone having a similar issue.

RESOLUTION:
uninstall the MQTT integration from HomeAssistant
uninstall the Mosquitto Broker from home assistant
Reboot home assistant
Reinstall the Mosquitto Broker, re-allowing the anonymous login needed for MQTT-all.py
Reinstall the MQTT Integtration

Hey presto, the sensors all started working.

I am assuming that you can not use broker usernames and passwords?