Is there a way to change how a script responded depending on which user clicked the button that fired it?
I have this script, which is triggered by a button in the dashboard. The problem is ‘trigger’ comes up as undefined. I assume this is because only automations have triggers. Is there a way to do this via a script? Or do I need to do it via automation?
Edit: I re-created this as an automation. But if you trigger an automation from the dashboard it appears there is no actual trigger.
Scripts don’t use triggers so I assume you have a button card that is calling the script.
The above script looks correct to me from an action point of view, if you create the above as an automation and use an actual button helper ‘input_button’ as the trigger then display the button entity in the front end then this will pass the user_id.
Example trigger for a input_button helper:
- platform: state
entity_id:
- input_button.your_button
Thanks for your help. I’ve recreated the script as an automation and used the input button helper.
Below is the event fired by the button, which contains the user_id. But the following automation does not work (it goes to default instead of the first condition). Looking at the event the trigger should be defined something like the following, but none work.
trigger.event.context.user_id → dictionary error
trigger.context.user_id → dictionary error
trigger.user_id → no error, but doesn’t work
Oh my god. I updated the wrong button to use the input button helper. So I spent the afternoon clicking on a button that was triggering the automation directly.
Thank you for your persistence! It now works.