DPHacks / picow-air

Pico W Air Quality Monitoring w/ PM 2.5 Sensor
MIT License
36 stars 6 forks source link

RFE: support for homeassistant autodiscovery #1

Open NeilHanlon opened 10 months ago

NeilHanlon commented 10 months ago

Heya! I just got my order from Tindie the other day and all is working well! I wanted to open an issue here about autodiscovery for homeassistant before I started working on implementing it, in case there was some preexisting work or something I was missing.

I've managed to get my sensor into HA using the following config in configuration.yaml, and I suspect it shouldn't be that hard to add a configuration setting which would emit an MQTT message to the right place to create the entities automagically--which I'm happy to poke at assuming it's not already underway :)

sensor:
  - state_topic: "enviro/picoair"
    name: "PM100 Environment"
    unit_of_measurement: 'µg/m³'
    value_template: "{{ value_json['pm100 env'] }}"

  - state_topic: "enviro/picoair"
    name: "Particles 0.3µm"
    unit_of_measurement: 'particles/cm³'
    value_template: "{{ value_json['particles 03um'] }}"

  - state_topic: "enviro/picoair"
    name: "PM100 Standard"
    unit_of_measurement: 'µg/m³'
    value_template: "{{ value_json['pm100 standard'] }}"

  - state_topic: "enviro/picoair"
    name: "Particles 2.5µm"
    unit_of_measurement: 'particles/cm³'
    value_template: "{{ value_json['particles 25um'] }}"

  - state_topic: "enviro/picoair"
    name: "PM2.5 Standard"
    unit_of_measurement: 'µg/m³'
    value_template: "{{ value_json['pm25 standard'] }}"

  - state_topic: "enviro/picoair"
    name: "PM10 Environment"
    unit_of_measurement: 'µg/m³'
    value_template: "{{ value_json['pm10 env'] }}"

  - state_topic: "enviro/picoair"
    name: "PM10 Standard"
    unit_of_measurement: 'µg/m³'
    value_template: "{{ value_json['pm10 standard'] }}"

  - state_topic: "enviro/picoair"
    name: "PM2.5 Environment"
    unit_of_measurement: 'µg/m³'
    value_template: "{{ value_json['pm25 env'] }}"

  - state_topic: "enviro/picoair"
    name: "Particles 0.5µm"
    unit_of_measurement: 'particles/cm³'
    value_template: "{{ value_json['particles 05um'] }}"

  - state_topic: "enviro/picoair"
    name: "Particles 1.0µm"
    unit_of_measurement: 'particles/cm³'
    value_template: "{{ value_json['particles 10um'] }}"

  - state_topic: "enviro/picoair"
    name: "Particles 100µm"
    unit_of_measurement: 'particles/cm³'
    value_template: "{{ value_json['particles 100um'] }}"

  - state_topic: "enviro/picoair"
    name: "Particles 50µm"
    unit_of_measurement: 'particles/cm³'
    value_template: "{{ value_json['particles 50um'] }}"

Thanks for the work on this!

camerahacks commented 5 months ago

A little late to the party. Did you see the MQTT functionality included in the firmware? My guess you just have to point the Pico W Air to the HA MQTT broker.

NeilHanlon commented 5 months ago

I am using the MQTT functionality in the firmware, but HA doesn't know what to do with it from there.

My suggestion here was that picow-air could emit messages formatted for MQTT autodiscovery, which would allow them to just be added to HA without restarting HA and changing the yaml for manual entities.

I looked around and found a python module which seems to help with formatting the autodiscovery messages. I might take a poke at a branch which adds a feature to enable HA autodiscovery over mqtt.

camerahacks commented 5 months ago

I see, I had misunderstood your question. I'll take a look.

regexcellent commented 1 week ago

Just wanted to chime in and say thanks @NeilHanlon for the config example! My cobbled together setup with InfluxDB and Grafana stopped working so I decided to finally take the plunge into Home Assistant. With your config I was able to get up and running with dashboard graphs in far less time than it took me to get my original setup working.