Problems with Sensor of sunset and delay as input number

Hello, for my shutter automation i have created a helper input.number for setup the delaytime in minutes after sunset as trigger. When HA is rebooted while delaytime is running, action aborts.
So I try to create a sensor as timestamp with sunset + delaytime and set as triggertime but i cant get it work

- sensor:
    - name: Beschattung nach Sonnenuntergang verzögert
      unique_id: beschattung_nach_sonnenuntergang_verzogert
      state: "{{ (state_attr('sun.sun', 'next_setting') | as_datetime | as_local + timedelta(minutes = states('input_number.beschattung_sonnenuntergang_verzogerung') | int(0))).timestamp() | timestamp_custom('%H:%M:%S', true)}}"


what’s wrong in my Code?

Find a similar topic but need another solution
https://community.home-assistant.io/t/trying-to-create-a-sensor-to-represent-a-10-minute-offset-to-sunrise/543830?u=joe5

I suggest you try what I had proposed for someone else who had a similar requirement:

For your application, you only need to create one of the two proposed Template Sensors (Sunset Offset) and then use it in an automation’s Time Trigger.

BTW, if you are trying to use your Template Sensor in a Time Trigger, it won’t work because its device_class property must be timestamp.

Ok, thanks! I will try this solution. Is there perhaps a solution with editable offset over UI with another helper?

Isn’t that the purpose of the Input Number you are using?

Right, can I replace this helper with the offsettime in the code?

I don’t understand what you want to do. Your previous post asked for “editable offset over UI with another helper” and your current post asks for “replace this helper with the offsettime in the code”.

So which is it? With or without the Input Number helper?

With editable Offset over UI I meant via a Input Number on the Dashboard. Sorry, hope that is now understandable.

- sensor:
    - name: Beschattung nach Sonnenuntergang verzögert
      unique_id: beschattung_nach_sonnenuntergang_verzogert
      device_class: timestamp
      state: >
        {{ state_attr('sun.sun', 'next_setting') | as_datetime +
          timedelta(minutes = states('input_number.beschattung_sonnenuntergang_verzogerung') | int(0)) }}

Thanks for the quick support!

1 Like