Statistics platform supplys a nice graph but I cant use the number in automations. shade controll

So I built a sensor that reports my yesterday max sun elevation. (as I dont know how to get the todays at noon, in the early morning, and its changing slowly enough that I dont realy care.)

I added to sensor.yaml:

# max sun elevation yesterday
- platform: statistics
  name: "Sun_Solar_Elevation-Maximum_Yesterday"
  entity_id: sensor.sun_solar_elevation
  state_characteristic: value_max
  max_age:
    hours: 48

and this gives me a nice graph with a line (and coresponding number) representing the hightes elevation the sun has had in the past 24h with two decimals. (asside form the first day if you start it after the highest elevation.)

now I try to use that in an automation with this.

condition: and
conditions:
  - condition: trigger
    id:
      - shade
  - condition: numeric_state
    entity_id: sensor.sun_solar_elevation_maximum_yesterday
    value_template: ""
    above: 20
    enabled: true
  - condition: template
    value_template: >-
      {{state_attr('weather.dwd_weather_berlin', 'forecast')[0]['temperature']
      >= 15 }}
  - condition: state
    entity_id: input_boolean.rolladen_eg_kuche_beschattung
    state: "on"

explanation: with AND

  • the trigger is run by azimuth -45 from the direction of the window (unshade to 100% open always runs at azimuth +45° from the window.)
  • when the elevation yesterday was above 20 (for test purposes, in real life it depends on location, for mine I would go with 40, as that was the average of what I manually activated the shutter in the past while at home)
  • when the forecast for today is above 15 (also for test purposes, in real life I would chose somewhere around 22-25)
  • and finally, if the shade option is active for that window shutter.

But when I test the elevation condition in automations I get:

In ‘numeric_state’: In ‘numeric_state’ condition: entity sensor.sun_solar_elevation_maximum_yesterday state ‘’ cannot be processed as a number

Í suspect I need to add a float somewhere, but I cant figgure out where and how that should look.

who could give me a clue?

Remove that. It just replaces your sensor value with an empty string.

1 Like

Oh, so obvious, thanks.

I do know exactly how that ended up in there… Ii used the UI to create the yaml, and accidentally copyied something into the template row of that condition, the template for the next conditon, I find that UI so confusing especially if one got several conditions in a row and such…

How ever I then deleted my wrongly pasted template. But then, in my opinion, the HA UI should have deleted that empty part of the template row in the code too.

Did I just happen to stumble over a bug?

Not sure, I don’t use the UI. I find yaml much easier to follow.

1 Like

I fully concure, but sometimes, if Im not fluent in the code, (thats mostly the case with me, still) I like to get started with the UI, and then go from there, but sometimes I just use the UI, and then such stuff happens.