pnbruckner / ha-sun2

Home Assistant Sun2 Sensor
The Unlicense
235 stars 22 forks source link

Trigger at elevation not working #100

Closed Spartacus68 closed 11 months ago

Spartacus68 commented 11 months ago

Hi,

I am trying to trigger on time_at_elevation but it is not working. Is this an issue or isnßt in working yet?

alias: SU_Eingangslicht_SU_SA
description: ""
trigger:
  - platform: time
    at: sensor.su_eingang
    id: Sonnenuntergang
  - platform: time
    at: sensor.sa_eingang
    id: Sonnenaufgang

in sun2.yaml:

      - time_at_elevation: -1.5
        direction: setting 
        icon: mdi:weather-sunset-down
        name: SU_Eingang
      - time_at_elevation: -1.5
        direction: rising 
        icon: mdi:weather-sunset-up
        name: SA_Eingang
pnbruckner commented 11 months ago

What version of sun2 are you using?

Spartacus68 commented 11 months ago

Hi pnbruckner,

thanks for reply. I got it to work! Was a mistake of mine, sorry!

But may I ask a question? I defined sunrise and senset with a customized elevation, that means that daylight (repective night) is defined between sunrise and sunset (sunset and sunrise). Is there an easy way to define customized daylight and night with sun2? Or how can I create a condition which is true during "night" respective "daylight"?

pnbruckner commented 11 months ago

Glad you got it working!

Is there an easy way to define customized daylight and night with sun2?

Not directly with the sun2 integration. However, it would be very simple to do with a template sensor:

template:
  - sensor:
      - name: Daylight
        unique_id: custom_daylight
        device_class: duration
        state_class: measurement
        unit_of_measurement: hr
        state: >
          {{
            (states('sensor.su_eingang')|as_datetime - states('sensor.sa_eingang')|as_datetime)
            .total_seconds()/3600
          }}

Or how can I create a condition which is true during "night" respective "daylight"?

Not exactly sure what you mean by "a condition". Do you mean an automation condition?

You could create a binary_sensor that is on (i.e., true) during your custom daylight, and another for night. E.g.,

template:
  - binary_sensor:
      - name: Day
        unique_id: custom_day
        state: >
          {{ states('sensor.sa_eingang')|as_datetime < now() <= states('sensor.su_eingang')|as_datetime }}
      - name: Night
        unique_id: custom_night
        state: "{{ is_state('binary_sensor.day', 'off') }}"

Then you could use those for automation conditions.

Spartacus68 commented 11 months ago

Hello pnbrucker,

very cool! with the binary_sensor! It works great. And yes, the question was, how I can use this as an condition for automations. I think I have the solution now! Many, many thanks for your great support.

Spartacus