Weather forecast sensor "sun next 3 hours"

Hi.

I need some help to write a template sensor.

For my heating control system i would like to check if it´s going to be “Sunny” for X(3) of hours in the next Y(5) number of hours.

I have the data from Met.on integration forecast Home_Hourly, but can´t figure how check the next 5 hours and return “Sunny” if 3 of them is “Sunny”

Help would be much appreciated.

Can you show the detailed data that this integration provides?
And what you have tried to put down as code?
It’s very difficult to help you when there is no detailed information provided.

Sorry, I have no code to provide, this is my first encounter with the need for a custom sensor, based on time, I have been reading up on Templates, dates and times - Home Assistant but is unable to figure how to use it…

This is the data from the sensor: (weather.home_hourly) from met.on integration

temperature: 2.3
humidity: 96
pressure: 1009.4
wind_bearing: 311.8
wind_speed: 23
attribution: >-
  Weather forecast from met.no, delivered by the Norwegian Meteorological
  Institute.
forecast:
  - condition: cloudy
    precipitation: 0
    precipitation_probability: 0.1
    temperature: 2.2
    datetime: '2021-04-11T18:00:00+00:00'
    wind_bearing: 307.6
    wind_speed: 24.5
  - condition: cloudy
    precipitation: 0
    precipitation_probability: 0
    temperature: 2.1
    datetime: '2021-04-11T19:00:00+00:00'
    wind_bearing: 309.6
    wind_speed: 21.6
  - condition: cloudy
    precipitation: 0
    precipitation_probability: 0
    temperature: 2.3
    datetime: '2021-04-11T20:00:00+00:00'
    wind_bearing: 304.4
    wind_speed: 20.9
  - condition: cloudy
    precipitation: 0
    precipitation_probability: 0.5
    temperature: 2.4
    datetime: '2021-04-11T21:00:00+00:00'
    wind_bearing: 302
    wind_speed: 22.3
  - condition: cloudy
    precipitation: 0
    precipitation_probability: 0.3
    temperature: 2.6
    datetime: '2021-04-11T22:00:00+00:00'
    wind_bearing: 296.2
    wind_speed: 23
  - condition: cloudy
    precipitation: 0
    precipitation_probability: 2
    temperature: 2.5
    datetime: '2021-04-11T23:00:00+00:00'
    wind_bearing: 285.8
    wind_speed: 22.7
  - condition: partlycloudy
    precipitation: 0
    precipitation_probability: 0.4
    temperature: 2.5
    datetime: '2021-04-12T00:00:00+00:00'
    wind_bearing: 291.2
    wind_speed: 25.9
  - condition: sunny
    precipitation: 0
    precipitation_probability: 0.1
    temperature: 1.5
    datetime: '2021-04-12T01:00:00+00:00'
    wind_bearing: 283.3
    wind_speed: 21.2
  - condition: sunny
    precipitation: 0
    precipitation_probability: 0.1
    temperature: 1.1
    datetime: '2021-04-12T02:00:00+00:00'
    wind_bearing: 269.1
    wind_speed: 20.2
  - condition: partlycloudy
    precipitation: 0
    precipitation_probability: 1
    temperature: 0.8
    datetime: '2021-04-12T03:00:00+00:00'
    wind_bearing: 260
    wind_speed: 20.5
  - condition: partlycloudy
    precipitation: 0
    precipitation_probability: 0
    temperature: 0.6
    datetime: '2021-04-12T04:00:00+00:00'
    wind_bearing: 259.1
    wind_speed: 20.5
  - condition: partlycloudy
    precipitation: 0
    precipitation_probability: 0
    temperature: 0.9
    datetime: '2021-04-12T05:00:00+00:00'
    wind_bearing: 262
    wind_speed: 20.9
  - condition: partlycloudy
    precipitation: 0
    precipitation_probability: 0
    temperature: 1.7
    datetime: '2021-04-12T06:00:00+00:00'
    wind_bearing: 259.5
    wind_speed: 21.2
  - condition: partlycloudy
    precipitation: 0
    precipitation_probability: 0.1
    temperature: 2.9
    datetime: '2021-04-12T07:00:00+00:00'
    wind_bearing: 264.9
    wind_speed: 23.4
  - condition: partlycloudy
    precipitation: 0
    precipitation_probability: 5.3
    temperature: 4
    datetime: '2021-04-12T08:00:00+00:00'
    wind_bearing: 268.7
    wind_speed: 27.7
  - condition: partlycloudy
    precipitation: 0
    precipitation_probability: 0.2
    temperature: 4.9
    datetime: '2021-04-12T09:00:00+00:00'
    wind_bearing: 266.9
    wind_speed: 29.5
  - condition: partlycloudy
    precipitation: 0
    precipitation_probability: 0.4
    temperature: 5.7
    datetime: '2021-04-12T10:00:00+00:00'
    wind_bearing: 265.4
    wind_speed: 29.9
  - condition: partlycloudy
    precipitation: 0
    precipitation_probability: 0.4
    temperature: 6.2
    datetime: '2021-04-12T11:00:00+00:00'
    wind_bearing: 263
    wind_speed: 31
  - condition: partlycloudy
    precipitation: 0
    precipitation_probability: 5.6
    temperature: 6.4
    datetime: '2021-04-12T12:00:00+00:00'
    wind_bearing: 260.8
    wind_speed: 31.7
  - condition: partlycloudy
    precipitation: 0
    precipitation_probability: 7.5
    temperature: 6.4
    datetime: '2021-04-12T13:00:00+00:00'
    wind_bearing: 259.4
    wind_speed: 32
  - condition: partlycloudy
    precipitation: 0
    precipitation_probability: 5
    temperature: 6.3
    datetime: '2021-04-12T14:00:00+00:00'
    wind_bearing: 255.8
    wind_speed: 31.7
  - condition: partlycloudy
    precipitation: 0
    precipitation_probability: 15.9
    temperature: 6
    datetime: '2021-04-12T15:00:00+00:00'
    wind_bearing: 253.8
    wind_speed: 30.6
  - condition: partlycloudy
    precipitation: 0
    precipitation_probability: 15.8
    temperature: 5.6
    datetime: '2021-04-12T16:00:00+00:00'
    wind_bearing: 250.5
    wind_speed: 30.2
  - condition: partlycloudy
    precipitation: 0
    precipitation_probability: 7.7
    temperature: 4.9
    datetime: '2021-04-12T17:00:00+00:00'
    wind_bearing: 247.5
    wind_speed: 28.4
friendly_name: Home Hourly

Ok, thanks.
Unfortunately my HA programming skills are not that advanced. Sorry, I don’t know how to help you :frowning:

No problem, thanks for trying, hope someone else can help me in the right direction.