I wonder if it is possible to use the passed device_id somehow in an automation service.
An example of what I am trying to do, this is my automation that is supposed to activate an alarm in my phone in X minutes from the time it is triggered by voice:
alias: Alarma
description: |-
Activa la alarma en X minuts.
trigger:
- platform: conversation
command:
- Activa (la alarma|l'alarma) en {time_amount} minuts
condition: []
action:
- service: notify.device_id
data:
message: command_activity
data:
intent_action: android.intent.action.SET_ALARM
intent_extras: >-
{% set alarm_time = now() +
timedelta(minutes=trigger.slots.time_amount|int) %} {{
'android.intent.extra.alarm.HOUR:' ~ alarm_time.hour|string ~
',android.intent.extra.alarm.MINUTES:' ~ alarm_time.minute|string ~
',android.intent.extra.alarm.SKIP_UI:true' }}
mode: single
So in service: notify.device_id I wanna replace device_id for the device_id from the device from where it was triggered.
It does not work even replacing “{{ device_id }}” by the real device_id.
From the documentation I can read this:
Be aware that you might want to change the actual service to whatever service you are actually using since notify.notify is shorthand for the first notify service the system can find and might therefore not be working as intended.
So maybe I need to use notify.platform_id there but not sure which platform_ids exists, maybe notify.android?
Yes, the device exists because my script works, but just for my device, what I want is for it to work with any device. The thing is that I don’t think device_id as a variable exists, I guess I need to get it from somewhere. Like when I get the sentence variable from trigger.slots.time_amount. I expect something like trigger.device_id. I understand this issue was about being able to pass the device_id to the pipeline so it can be used inside like in my case.
But maybe I’m wrong assuming that, in that case I’ll create a feature request because this would be really usefull for many use cases.
Doesn’t trigger.device_id work? Or maybe trigger.to_state.device_id? On the other hand, that sounds even more wrong than the first one. You see, I’m not that far into Assist functions yet, so it’s happy guessing
What I can think of as well, isn’t this “variable” inside the response object? That would go to something like response.device_id.
And another guess:
According to the code, it should be available at the same level as conversation_id, so maybe the easiest of it all, like device_id?
I’m just guessing here, so don’t take any of this serious. But please let us know, how you come along. I’m not there yet, still in the phase where I have to work with custom_sentences and configuring “alias” names for every device… But I’ll get there sooner or later, and I’m quite sure I already have use cases where I also need to know the device_id.
So what you got there is that basically device_id is a function and if you pass to it an entity_id it will give you its device_id. Not what we need right now.
trigger.device_id Returned an empty string. trigger.to_state.device_id Returned the following error Error rendering data template: UndefinedError: 'dict object' has no attribute 'to_state' response.device_id Returned the following error Error rendering data template: UndefinedError: 'response' is undefined
So the trigger is the conversation entity, not the device. So I think I need to create a feature request for it.
This could also allow for more complex scenarios using scripts where you could for example just say ´turn on the lights´ and since it will know from which mic it comes the command from could turn off the lights of the right room.