Subtracting time from a date time helper and splitting the hours/minutes

I have an automation that passes variables to a script which sends data to my solar inverter via the solarman integration. This takes values for hours and minutes to write to registers in the inverter to control when it charges the battery

I have scenario where I want to set the battery to charge say between 06:30 and 07:00 so I have a helper set to 07:00 Id like to be able to subtract the 30 minutes but then split the time to get 06 & 30

I know i can use:

{{ state_attr(‘input_datetime.targettime’, ‘hour’) }}
{{ state_attr(‘input_datetime.targettime’, ‘minute’) }}
to return the hours and minutes separately but how would i subtract the 30 minutes from the helper before doing it?

Or should I just use another helper/template sensor to store the start time separately?

{% set t = today_at(states('input_datetime.targettime'))-timedelta(minutes=30) %}
{{ t.hour }}
{{ t.minute }}

Thanks Troon

1 Like