Turn on water heater in the evening on cloudy days

Hello.
I am trying to automate turning on my water heater at the evening only if it was more than 50% cloudy between 10am and 3pm on that day.

I want to specifically check for these times as these are the times my water heater panels get sun.

What’s the best way to achieve this ?

P.S. I tried asking Gemini, it gave me some options that didn’t work but the problem with LLMs is that HA is moving too fast for them and things are changing so their answers are based on outdated information (due to the cutoff). If I have the right direction, I can direct it to provide me a good answer.

Thank you

To clarify…

How are you measuring “50% cloudy”? Using light levels, weather reports or energy generated by the panels? The last might be best if you can measure it.

If light etc., do you mean 50% cloudy for the whole of that period, or at any point in that period?

Good point, using weather integration, condition one of

      - cloudy
      - partlycloudy
      - fog
      - hail
      - lightning
      - lightning-rainy
      - pouring
      - rainy
      - snowy
      - snowy-rainy
      - windy-variant
      - exceptional

I want to measure if it had one of these states for more than 50% of the time during 10am and 3pm. I think the weather coverage report is granular down to 1 hour

A cheap and cheerful way might be to have an hourly automation checking those weather conditions, incrementing a counter between 10am and 3pm. In the evening, if the counter >3 (assuming 6 updates) turn on the water heater and reset the counter.

If your weather entity has a cloud coverage attribute you could use that as a single condition. Mine doesn’t, but from the docs it may be provided as a percentage.

1 Like

Sound like a good idea. What HA components would I need in order to set it up ?
Counter helper ?
How would I reset the counter helper every day at 10am, at the beginning of thje new cycle ?

Another option maybe would be to use History Stats to measure between 10am and 3pm how much time the state was cloudy:

sensor:
  - platform: history_stats
    unique_id: cloudy_percentage_today_water_heater
    name: Cloudy Percentage Today
    entity_id: weather.forecast_home
    state:
      - cloudy
      - partlycloudy
      - fog
      - hail
      - lightning
      - lightning-rainy
      - pouring
      - rainy
      - snowy
      - snowy-rainy
      - windy-variant
      - exceptional
    type: ratio
    start: "{{ today_at('10:00') }}"
    end: "{{ today_at('15:00') }}"
1 Like

Writing here for the sake of others and for my own future reference.

My weather sensor has these state attributes (example):

temperature: 16.4
dew_point: 13.5
temperature_unit: °C
humidity: 83
cloud_coverage: 68.7   # <----- Notice this attribute
uv_index: 2.1
pressure: 1020.2
pressure_unit: hPa
wind_bearing: 303.6
wind_speed: 20.5
wind_speed_unit: km/h
visibility_unit: km
precipitation_unit: mm
attribution: >-
  Weather forecast from met.no, delivered by the Norwegian Meteorological
  Institute.
friendly_name: Forecast Home
supported_features: 3

Using this cloud_coverage attribute I was able to

  1. Define Template Sensor that extracts the cloud_coverage attribute from weather.forecast_home and makes it a sensor with a percentage value:
sensor:
  # used to track the entity attribute cloud coverage of weather forecast
  - platform: template
    sensors:
      cloud_coverage_percentage:
        friendly_name: "Cloud Coverage Percentage"
        unit_of_measurement: "%"
        value_template: "{{ state_attr('weather.forecast_home', 'cloud_coverage') }}"
        device_class: humidity # Although it's not humidity, this provides a % unit
  1. Statistics Sensor that calculates the average of the sensor I’ve just defined over a sliding 5-hour window. When checked, it gives you an average of last 5 hours:
  - platform: statistics
    unique_id: average_cloud_coverage_today_stats
    name: Average Cloudy Percentage Today
    entity_id: sensor.cloud_coverage_percentage
    state_characteristic: mean # Calculate the average (mean)
    sampling_size: 500 # Optional: Adjust sampling size if needed
    max_age: 05:00:00 # Duration of 5 hours (10am to 3pm)

Now, the problem is that I only want to (possibly) turn on the water heater in the evening, so if I sample that statistics sensor at that time, it will give me the last 5 hours which include times that are out of my 10am-3pm time window. Therefor, I needed to sample the sensor at 3pm and store the value somewhere.

  1. Input Number to stores the average cloud coverage percentage captured at 3pm each day, used in the water heater automation condition:
input_number:
  cloud_coverage_3pm_average_value:
    name: "Cloud Coverage Average"
    unit_of_measurement: "%"
    min: 0
    max: 100
    step: 1
    mode: box # or slider, or auto

So basically, I expose the cloud_coverage from the weather entity, I sample it using statistics sensor for the last 5 hours. At 3pm, when the sun no longer shine on my water heater panels I have an automation set up to take the current value from the statistics sensor and store it in an input number.
That number could, for example, be equal to 54 which means that during the last 5 hours, there was an average of 54% cloud coverage.

Once I have the input number stored daily which tells me how much cloud coverage was during the sun hours, I can easily define an automation to turn on the water heater if cloud coverage was > 40% for example.