huizebruin / Home-Assistant-Config

šŸ  My huizebruin Home Assistant configuration, Be sure to šŸŒŸ this repository for updates! huizebruin
MIT License
42 stars 9 forks source link

Possible improvement for pollen #8

Closed golles closed 3 years ago

golles commented 3 years ago

Hi, I found your pollen integration and I wanted to let you know that I'm really happy you shared this, I copied it and made some improvements, maybe interesting for you as well? Pick what you like, discard what you don't šŸ˜‰

Improvements:

I've got a strong preference for attributes over different sensors, as it feels like polluting to create sensors for things that could be an attribute also there is no longer a link between the sensors. Also if you click on one of these entities, the more-info will be shown and there you see all the attributes, I personally find that nice/useful to have a clean UI and more information just one click away:

Schermafbeelding 2021-05-13 om 14 43 01

pollen.yaml

sensor:
  - platform: rest
    name: pollen_data
    scan_interval: 900
    resource_template: https://api.ambeedata.com/latest/pollen/by-lat-lng?lat={{ state_attr("zone.home", "latitude") }}&lng={{ state_attr("zone.home", "longitude") }}
    value_template: >-
      {{ value_json.message}}
    headers:
      content-type: application/json
      x-api-key: !secret ambee-api
    json_attributes_path: data[0]
    json_attributes:
      - Count
      - Risk
      - Species
      - updatedAt

  - platform: template
    sensors:
      pollen_bomen:
        friendly_name: Bomen
        icon_template: mdi:tree
        value_template: >-
          {% set state = state_attr("sensor.pollen_data", "Risk").tree_pollen %}
          {% if state == "Low" %} Weinig
          {% elif state == "Moderate"%} Matig
          {% elif state == "High"%} Hoog
          {% elif state == "Very High"%} Zeer hoog
          {% else %}Onbekend{% endif %}
        attribute_templates:
          Totaal: >-
            {{ state_attr("sensor.pollen_data", "Count").tree_pollen }} /mĀ³
          Els: >-
            {{ state_attr("sensor.pollen_data", "Species").Tree.Alder }} /mĀ³
          Berk: >-
            {{ state_attr("sensor.pollen_data", "Species").Tree.Birch }} /mĀ³
          Coniferen: >-
            {{ state_attr("sensor.pollen_data", "Species").Tree.Cypress }} /mĀ³
          Iep: >-
            {{ state_attr("sensor.pollen_data", "Species").Tree.Elm }} /mĀ³
          Hazelaar: >-
            {{ state_attr("sensor.pollen_data", "Species").Tree.Hazel }} /mĀ³
          Eik: >-
            {{ state_attr("sensor.pollen_data", "Species").Tree.Oak }} /mĀ³
          Den: >-
            {{ state_attr("sensor.pollen_data", "Species").Tree.Pine }} /mĀ³
          Plataan: >-
            {{ state_attr("sensor.pollen_data", "Species").Tree.Plane }} /mĀ³
          Populier: >-
            {{ state_attr("sensor.pollen_data", "Species").Tree["Poplar / Cottonwood"] }} /mĀ³

      pollen_grassen:
        friendly_name: Grassen
        icon_template: mdi:grass
        value_template: >-
          {% set state = state_attr("sensor.pollen_data", "Risk").grass_pollen %}
          {% if state == "Low" %} Weinig
          {% elif state == "Moderate"%} Matig
          {% elif state == "High"%} Hoog
          {% elif state == "Very High"%} Zeer hoog
          {% else %}Onbekend{% endif %}
        attribute_templates:
          Totaal: >-
            {{ state_attr("sensor.pollen_data", "Count").grass_pollen }} /mĀ³
          Gramineae: >-
            {{ state_attr("sensor.pollen_data", "Species").Grass["Grass / Poaceae"] }} /mĀ³

      pollen_onkruiden:
        friendly_name: Onkruiden
        icon_template: mdi:grass
        value_template: >-
          {% set state = state_attr("sensor.pollen_data", "Risk").weed_pollen %}
          {% if state == "Low" %} Weinig
          {% elif state == "Moderate"%} Matig
          {% elif state == "High"%} Hoog
          {% elif state == "Very High"%} Zeer hoog
          {% else %}Onbekend{% endif %}
        attribute_templates:
          Totaal: >-
            {{ state_attr("sensor.pollen_data", "Count").weed_pollen }} /mĀ³
          Amaranten/Ganzenvoet: >-
            {{ state_attr("sensor.pollen_data", "Species").Weed.Chenopod }} /mĀ³
          Bijvoet: >-
            {{ state_attr("sensor.pollen_data", "Species").Weed.Mugwort }} /mĀ³
          Brandnetel: >-
            {{ state_attr("sensor.pollen_data", "Species").Weed.Nettle }} /mĀ³
          Ambrosia: >-
            {{ state_attr("sensor.pollen_data", "Species").Weed.Ragweed }} /mĀ³

Curious to hear your feedback, also feel free to close this issue whenever you want

huizebruin commented 3 years ago

Thanks Sander for sharing this to me. I combined your code and mine to get a little more information on my home dashboard I have updated my code and update it on github also.

185973657_919179982210529_7633268133819086340_n Front dashboard.

186511980_482674656388087_4727968442026259368_n When i click on the tree.

186464443_1078333842576917_1577703187911297854_n When i click on the grass.