Sunload sensor for Home Assistant
https://github.com/barneyman/sunload.git
I originally tried to do this entirely as a blueprint but quickly realised automations
are not really great at choose, the automations can be made significantly simpler if
logic is deferred to sensors.
This can be achieved in configuration.yaml - see appendix at the bottom - but I threw
this platform together.
sun.sun attributes
sensor.sunload_elevationsensor.sunload.azimuthEvery instance gets a sensor of the form "sensor.sunload_{}".format(INSTANCE_NAME)
inazimuth, bool - the sun is between the azimuth limits for this instanceinelevation , bool - the sun is between the elevation limits for this instancestate, bool - inazimuth and inelevationconfig/custom_components directory on your HA install, then clone this
repo
git clone https://github.com/barneyman/sunload.git
Restart your HA, then change configuration/yaml, then restart HA once again - HA will complain about the addon being
untested by their team.
Deleting the config entries will stop this code executng. When not used, the sunload
directory can be removed
sunload:
instances:
# this will create sensor.sunload_northside
- name: northside
azimuth:
min: 70
max: 350
elevation:
# min and max for elevation are optional
min: 5
# this will create sensor.sunload_southside
- name: southside
azimuth:
min: 330
max: 270
elevation:
# min and max for elevation are optional
min: 5
- alias: reduce northside sunload
trigger:
# when sun is on the north face
platform: state
entity_id:
- sensor.sunload_northside
to: True
condition:
# if i'm home and the forecast > 30 degs
- condition: and
conditions:
- condition: numeric_state
# this is a template sensor i created from {{ states.weather.beachhouse.attributes["temperature"] |float() }}
entity_id: sensor.forecast_temp
above: 30
- condition: state
entity_id:
- device_tracker.galaxy_note10
state: 'home'
action:
- service: cover.close_cover
entity_id: cover.north_blinds
- alias: open northside sunload
trigger:
# when sun is off north face
platform: state
entity_id:
- sensor.sunload_northside
to: False
condition:
# if i'm home
- condition: state
entity_id:
- device_tracker.galaxy_note10
state: 'home'
action:
- service: cover.open_cover
entity_id: cover.north_blinds`
template:
- sensor:
- name: "Sun Azimuth"
unit_of_measurement: "ยฐ"
state_class: "measurement"
state: >
{{ state_attr('sun.sun', 'azimuth') }}
- name: "Sun Elevation"
unit_of_measurement: "ยฐ"
state_class: "measurement"
state: >
{{ state_attr('sun.sun', 'elevation') }}
- binary_sensor:
- name: Sun Azimuth Test
state: >
{{ states.sensor.sun_azimuth.state | int() < 70 and states.sensor.sun_azimuth.state |int() > 5 }}
- name: Sun Elevation Test
state: >
{{ states.sensor.sun_elevation.state | int() > 5 and states.sensor.sun_elevation.state | int() < 60 }}
- name: Sun Azimuth And Elevation Test
state: >
{{ states.sensor.sun_elevation_test.state and sensor.sun_azimuth_test.state < 60 }}