Background: I have an automation that should trigger every other minute between 7:30pm and 8:00pm. I have this part working by triggering every 2 minutes (/2) of 7pm then “and if” after 7:29pm.
Next I’d like to test the value of a sensor against a value that varies based on when the trigger happens. So, at 7:30 the “and if” condition is sensor value > 130 - minute_time_of_trigger. I’m thinking this might work for me ‘{{ sensor > 130 - strptime(now(), “%M”) }}’
What I would like to know: is there is a way to access the actual time that the automation was triggered within a condition rather than using now() ?
### Trigger every 2 minutes of the 19th hour
### and if the time is after 7:29 PM and before 7:57 PM and the day is Monday, Tuesday, Wednesday, Thursday, or Friday
### and if template:
{{ int(states('sensor.envoy_XXXXXXXXXXXX_battery')) > 130-state_attr('automation.solar_evening_dg_activate', 'last_triggered').minute }}
### the battery item is a simple percentage (0-100% of battery charge)
### this state_attr is referring to itself (this automation)
...
load new enphase tariff to export battery to grid
...
send persistent message: >-
Activated at \:{{ state_attr('automation.solar_evening_dg_activate',
'last_triggered').minute }} with {{
int(states('sensor.envoy_XXXXXXXXXX_battery')) }}\% left.
The idea is to export battery power to the grid starting near the end of my peak time, working forwards from 7:30pm with formula that varies by time of day and available battery % to estimate if we have enough battery to both export to grid and run the home load until 8pm
This is for winter electric rates where peak $$ is about 22% higher than off-peak. During summer, peak $$ is 81% higher than off-peak, so I will adjust the formula to supply more battery to the grid, by starting sooner to enable longer discharge to grid, and also allow more of battery to be used, while still saving some for home load and emergency usage.