Combine states of one entity


My weather integration (KNMI) has multiple states e.g. rain, cloudy, lightning etc. Is it possible to combine these into one state (e.g. bad weather) that can be used as a condition in automations?

Thanks for any input!

Yes, with a template sensor. You’d build the if-then logic to determine if the weather is good or bad.


To follow up on that, I have little knowledge on yaml and how to do the above correctly. I started with the following but since I don’t really know what I’m doing, I’ll have to ask again. Also I guess there must be an easier way to do this, perhaps use if not for the states of the entity that don’t represent bad weather.

  - sensor:
      - name: "Slecht weer"
        state: >
          {% if is_state('weather.knmi.thuis', 'Gedeeltelijk bewolkt') %}
            slecht weer
          {% elif is_state('weather.knmi.thuis', 'Bewolkt') %}
            slecht weer
          {% elif is_state('weather.knmi.thuis', 'Rainy') %}
            slecht weer
          {% else %}
            goed weer
          {% endif %}