PMS5003 dans boitier Ikea Vindriktning

Bonsoir,

Le capteur Ikea HS à l’été dernier (surchauffe) et ayant un PMS5003 avec un ESP-12F D1 mini.
Pour quoi ne pas se servir du boitier et d’ajouter 4 leds au projet.

La photo:

Le code sous ESPHome sur une idée de https://forum.airgradient.com/t/sharing-my-experiences/152

esphome:
  name: qualite-air-led
  friendly_name: qualite-air-led

esp8266:
  board: esp01_1m

# Enable logging
logger:
  baud_rate: 0   
  level: DEBUG 
  esp8266_store_log_strings_in_flash: False

# Enable Home Assistant API
api:
  encryption:
    key: "votrecleavous"

ota:
  password: "votrepasswordavous"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: 192.168.1.240
    gateway: 192.168.1.1
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Qualite-Air-Led Fallback Hotspot"
    password: "idemavous"

captive_portal:

uart:
  rx_pin: GPIO2 #D4
  baud_rate: 9600
  
sensor:
  - platform: pmsx003
    type: PMSX003
    pm_1_0:
      name: "particule_1-0"
      id: pm1
      filters:
        - sliding_window_moving_average:
            window_size: 30
            send_every: 30
    pm_2_5:
      name: "particule_2-5"
      id: pm_2_5
      filters:
        - sliding_window_moving_average:
            window_size: 30
            send_every: 30
    pm_10_0:
      name: "particule_10-0"
      id: pm_10
      filters:
        - sliding_window_moving_average:
            window_size: 30
            send_every: 30
  - platform: template
    name: "particule_2-5 average"
    id: pm_2_5_avg_24h
    icon: mdi:chemical-weapon
    unit_of_measurement: µg/m³
    lambda: |-
      return id(pm_2_5).state;
    update_interval: 60s
    filters:
      - sliding_window_moving_average:
          window_size: 1440  # = 24 hours x 60 minutes
          send_every: 1
    on_value:
      then:
        - script.execute: update_aqi
  - platform: template
    name: "particule_10-0 average"
    id: pm_10_avg_24h
    icon: mdi:chemical-weapon
    unit_of_measurement: µg/m³
    lambda: |-
      return id(pm_10).state;
    update_interval: 60s
    filters:
      - sliding_window_moving_average:
          window_size: 1440  # = 24 hours x 60 minutes
          send_every: 1
    on_value:
      then:
        - script.execute: update_aqi

text_sensor:
  - platform: template
    name: "Airgradient Air Quality Index"
    id: aqi
    icon: mdi:air-filter
    
script:
  - id: update_aqi
    mode: restart
    then:
      - if:
          condition:
            or:
              - sensor.in_range:
                  id: pm_2_5_avg_24h
                  above: 25
              - sensor.in_range:
                  id: pm_10_avg_24h
                  above: 50
          then:
            - text_sensor.template.publish:
                id: aqi
                state: Tres Mauvais
            - script.execute: show_tr_bad
          else:
            - if:
                condition:
                  or:
                    - sensor.in_range:
                        id: pm_2_5_avg_24h
                        above: 20
                    - sensor.in_range:
                        id: pm_10_avg_24h
                        above: 40
                then:
                  - text_sensor.template.publish:
                      id: aqi
                      state: Mauvais
                  - script.execute: show_bad
                else:
                  - if:
                      condition:
                        or:
                          - sensor.in_range:
                              id: pm_2_5_avg_24h
                              above: 10
                          - sensor.in_range:
                              id: pm_10_avg_24h
                              above: 20
                      then:
                        - text_sensor.template.publish:
                            id: aqi
                            state: Mediocre
                        - script.execute: show_acceptable
                      else:
                        - text_sensor.template.publish:
                            id: aqi
                            state: Bon
                        - script.execute: show_good

    # Configuration for showing AQI status with the RGB LED
  - id: show_tr_bad
    then:
      - light.turn_on:
          id: rgb_led
          brightness: 25%
          red: 80%
          green: 0%
          blue: 20%
  - id: show_bad
    then:
      - light.turn_on:
          id: rgb_led
          brightness: 25%
          red: 100%
          green: 60%
          blue: 20%
  - id: show_acceptable
    then:
      - light.turn_on:
          id: rgb_led
          brightness: 25%
          red: 100%
          green: 87%
          blue: 20%          
  - id: show_good
    then:
      - light.turn_on:
          id: rgb_led
          brightness: 25%
          red: 0%
          green: 60%
          blue: 40%
interval:
  - interval: 120s
    then:
      - switch.turn_on: pms_set
      - delay: 20s
      - switch.turn_off: pms_set                
switch:
  - platform: gpio
    pin: 
      number: GPIO0 #D3
    id: pms_set
    name: "Debut mesure"

  - platform: restart
    name: "pms_restart"

light:
  - platform: neopixelbus
    type: GRB
    variant: WS2812x
    pin: GPIO4
    num_leds: 4
    name: "4 leds"
    id: rgb_led

en test et après il suffira de remonter dans le boitier

Bonjour

Modification pour éteindre les leds de 22 heures à 8:59
ajout de

time:
  - platform: homeassistant
    id: ha_time

Et modification pour automatiser l’extinction à reproduire pour id show_*


  - id: show_tr_bad
    then:
      - if:
          condition:
            - lambda: 'return id(ha_time).now().hour < 22 && id(ha_time).now().hour > 8 ;'
          then:
            - light.turn_on:
                id: rgb_led
                brightness: 20%
                red: 80%
                green: 0%
                blue: 20%
          else:
            - light.turn_off:
                id: rgb_led
1 « J'aime »