#Script is being affected by my time zone and not sure why?

1 messages · Page 1 of 1 (latest)

feral scaffold
#

I have the below script just to simply subtract 15 minutes from a datetime helper, but for some reason as well as doing that it's adding an hour. I'm in BST which is UTC+1 so that must be where it's coming from, but I have no idea why???

I'm reading the current value as a timestamp and setting it in the action as a timestamp, the UNIX epoch shouldn't move depending on timezone!

action: input_datetime.set_datetime metadata: {} data: timestamp: >- {{state_attr('input_datetime.next_morning_alarm', 'timestamp') - 900}} target: entity_id: input_datetime.next_morning_alarm

half raptor
#

I find it easier to do it with datetime objects and timedelta:

action: input_datetime.set_datetime
metadata: {}
data:
  datetime: |
    {{state_attr('input_datetime.next_morning_alarm')|as_datetime|as_local
    - timedelta(minutes=15) }}
target:
  entity_id: input_datetime.next_morning_alarm
feral scaffold
#

Thanks, I gave that a try, got this error

"Error rendering data template: TypeError: state_attr() missing 1 required positional argument: 'name'"

So added ", 'timestamp'" to state_attr and now it's doing the same thing again, adding an extra hour for some reason.

#
metadata: {}
data:
  datetime: |
    {{state_attr('input_datetime.next_morning_alarm', 'timestamp')|as_datetime|as_local
    - timedelta(minutes=15) }}
target:
  entity_id: input_datetime.next_morning_alarm```
weak harness
#

He meant:

action: input_datetime.set_datetime
metadata: {}
data:
  datetime: |
    {{ states('input_datetime.next_morning_alarm')|as_datetime|as_local
    - timedelta(minutes=15) }}
target:
  entity_id: input_datetime.next_morning_alarm
#

But are you using a date and time input_datetime

#

Or time only?

#

In case it's time only, you can use

action: input_datetime.set_datetime
metadata: {}
data:
  datetime: |
    {{ today_at(states('input_datetime.next_morning_alarm')) - timedelta(minutes=15) }}
target:
  entity_id: input_datetime.next_morning_alarm