Using entity attribute data

What I want to do:

Get the duration time of a scheduled water zone to figure out how long before sunset to start watering.

What I have: The entity in home assistant for the watering zone has an attribute “data.attributes.Duration” which give me “117 minutes”.

How do use the value “117 minutes” to start the zone 117 minutes before sunset.
I usually use bigtimer node to schedule or trigger my events, but for this I am thinking I might need a function node to trigger this.

Hi there, Instead of using a function node, if you are ok with using templating, You can try this out. Also I am using delay node with variable delay. But first of all you need to enable iso time sensor in HA which is a part of this flow.

The flow code is below. You have change one thing in it i,e replace the entitiy_id in the template with the entity id of your sensor from which you get the duration.

[{"id":"1f109af6.72df25","type":"api-render-template","z":"51045e07.bbf87","name":"Delay Calculation","server":"d177950.2a5aa68","template":"{{ (as_timestamp(state_attr('sun.sun', 'next_setting'))- as_timestamp(states.sensor.date_time_iso.state) - (state_attr('entity_id', 'duration')| int * 60) )* 1000}}","resultsLocation":"delay","resultsLocationType":"msg","templateLocation":"template","templateLocationType":"msg","x":310,"y":80,"wires":[["88ea732d.f47a5"]]},{"id":"985e0539.b72b18","type":"inject","z":"51045e07.bbf87","name":"","props":[{"p":"time","v":"","vt":"date"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 12 * * *","once":false,"onceDelay":0.1,"topic":"","x":150,"y":80,"wires":[["1f109af6.72df25"]]},{"id":"5cd7e6f1.e642c8","type":"debug","z":"51045e07.bbf87","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":610,"y":80,"wires":[]},{"id":"88ea732d.f47a5","type":"delay","z":"51045e07.bbf87","name":"","pauseType":"delayv","timeout":"100","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":480,"y":80,"wires":[["5cd7e6f1.e642c8"]]},{"id":"d177950.2a5aa68","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

There is also one more think you have to keep track of I have set this flow to trigger itself at 12 in the noon, you can change it but make sure it is before the set alarm.