Count if Icon code is 1,2,3


I am trying to find the total amount of sun hours for an internal calculation for Eto for my sprinkler system. One thought is to count the sun hours via an Icon code inside the environment Canada integration. How it would work is that every hour it looks at the integration and if the numeric code (example a 1, 2 or 3) is seen it increments a counter by one and at the end of the day the total is equal to the number of sun hours and then it resets at midnight. Any ideas on how to tackle this, I assume it is simple for someone that knows what they are doing?

Below, it is currently sunny and icon code is 1, earlier in the day icon code was 3 (partially sunny)

That would be ok for a single value (example 1) and based on my experience with HA but how would you allow it to count if it where a 1 or 2 or 3?

History Stats supports a list of acceptable state values, but use the time method directly instead of count:

  - platform: history_stats
    name: Hours of Sun
    entity_id: sensor.xxxxxxx_icon_code
      - "01"
      - "02"
      - "03"
    type: time
    start: "{{ today_at() }}"
    end: "{{ now() }}"

If you do it with count as the type there can be issues since it will only count up when the state changes from a value not in the list to one in the list, changes between listed states don’t increment the sensor’s count.

1 Like

Oh cool, I did not know you could do that with multiple states, I will give it a try and report back, thank you!

Works great thank you @Didgeridrew