Hi there - I’m new-ish to this world - blown away by the quality of the work available and the power of the platform!
I’m trying to write a trigger that will fire precisely (<=1sec) at the end of any given playing music track. This is initially quite clumsy as there isn’t an end-time exposed by Media Player, but I’ve calculated it with this code:
{{ (as_timestamp(now()) + state_attr('media_player.thybris', 'media_duration') - (state_attr('media_player.thybris', 'media_position') + as_timestamp(now()) - as_timestamp(state_attr('media_player.thybris', 'media_position_updated_at')))) | timestamp_custom('%H:%M:%S', true) }}
This, when viewed in Developer tools, gives me a great second-accurate timestamp. But where I struggle is the next step. I thought I’d set a helper with this value, using this automation:
alias: Set end of track helper value
description: ""
trigger: []
condition: []
action:
- service: input_datetime.set_datetime
metadata: {}
data:
time: >-
{{ now.timestamp(as_timestamp(now()) +
state_attr('media_player.thybris','media_duration') -
(state_attr('media_player.thybris', 'media_position') +
as_timestamp(now()) -
as_timestamp(state_attr('media_player.thybris','media_position_updated_at'))))
| timestamp_custom('%H:%M:%S', true) }}
target:
entity_id: input_datetime.end_of_current_track_time
mode: single
(for testing, there’s no automation trigger, I’m doing that manually)
Unfortunately this simply doesn’t work. The logs say:
Template variable error: ‘function object’ has no attribute ‘timestamp’ when rendering ‘{{ now.timestamp(as_timestamp(now()) + state_attr(‘media_player.thybris’,‘media_duration’) - (state_attr(‘media_player.thybris’, ‘media_position’) + as_timestamp(now()) - as_timestamp(state_attr(‘media_player.thybris’,‘media_position_updated_at’)))) | timestamp_custom(’%H:%M:%S’, true) }}’
This makes me wonder if I’m using template syntax where I shouldn’t be, perhaps? Can anyone help with what I’m doing wrong? Any and all help gratefully received!
Many thanks,
Kit