Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context user_id ist not propagated when an automation is triggered by a MobileApp event. #90669

Open
Xyaren opened this issue Apr 2, 2023 · 11 comments

Comments

@Xyaren
Copy link
Contributor

Xyaren commented Apr 2, 2023

The problem

The following Situatuation:

I have:

  • An Android Phone using the latest Homeassistant Android App
  • A Helper boolean (H1)
  • An autoamtion: (A1)
    • Trigger:
      • (Manual Run) (T0)
      • Notification Action Event for MY_ACTION (T1)
      • Notification Dismiss Event (T2)
  • When triggered by T1/T2 toggle H1 by service call, otherwise create notification

Sequence of operation:

  1. Create Helper H1
  2. Create Automation A1
  3. Run Automation A1 to create a notification on the device.
  4. Press the Notification Action
  5. Automation runs through Trigger T1 and toggles H1

I would expect, that the helper logbook shows, that the helper was toggled by the user, that performed the action.
Unfortunately that is not the case.
(Note that the user is not mentioned in the logbook entry)
image

When I toggle the helper manually I can see my Username attached to the logbook entry:
image

In the attached event log you can see, that the user_id is present in the mobile_app_notification_action event but not propagated to the automation call.

Expectation

My expectation would be, that if i.e. a light is turned on by an automation, that is triggered by an event, caused by a user, this user will appear in the corresponding logbook entry.

Ideally there would be an indication, of the responsible user and automation that contributed to the status change.

What version of Home Assistant Core has the issue?

core-2023.3.6

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Automation, Mobile App

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

alias: Automation to test Test User_id Context propagation
description: ""
trigger:
  - platform: event
    event_type: mobile_app_notification_action
    event_data:
      tag: test
      action: MY_ACTION
    id: trigger1
  - platform: event
    event_type: mobile_app_notification_cleared
    event_data:
      tag: test
    id: trigger2
condition: []
action:
  - if:
      - condition: or
        conditions:
          - condition: trigger
            id: trigger1
          - condition: trigger
            id: trigger2
        alias: If triggered by notification action
    then:
      - service: input_boolean.toggle
        data: {}
        target:
          entity_id: input_boolean.test_bool
    else:
      - service: notify.notify
        data:
          message: Test Notification
          title: Test
          data:
            persistent: false
            importance: default
            sticky: true
            color: "#1e8fc3"
            channel: Test
            tag: test
            visibility: public
            notification_icon: mdi:flask
            priority: NORMAL
            clickAction: noAction
            actions:
              - action: MY_ACTION
                title: Action
mode: queued
max: 10

Anything in the logs that might be useful for us?

No response

Additional information

Events in order of occurance caused by pressing the "Action" on the mobile app:

Event 1

event_type: mobile_app_notification_action
data:
  notification_icon: mdi:flask
  sticky: "true"
  tag: test
  color: "#1e8fc3"
  title: Test
  webhook_id: aa87d0f3497d28e38b01e7f37eac4d0883b7e7278a5bb82a2d0164af64782e41
  channel: Test
  clickAction: noAction
  message: Test Notification
  action_1_title: Action
  action_1_key: MY_ACTION
  visibility: public
  importance: default
  server_id: "1"
  action: MY_ACTION
  device_id: 9f6cc8978c151403
origin: REMOTE
time_fired: "2023-04-02T12:22:54.216364+00:00"
context:
  id: 01GX0YQ8G85NC539YVJ9FHRWR3
  parent_id: null
  user_id: d14c52a5cc114da28fa782cb6e010299

Event 2

event_type: automation_triggered
data:
  name: Test User_id Context propagation
  entity_id: automation.test_user_id_context_propagation
  source: event 'mobile_app_notification_action'
origin: LOCAL
time_fired: "2023-04-02T12:22:54.218709+00:00"
context:
  id: 01GX0YQ8GABC8MJF0ZGPCVK46H
  parent_id: 01GX0YQ8G85NC539YVJ9FHRWR3
  user_id: null

Event 3

event_type: state_changed
data:
  entity_id: automation.test_user_id_context_propagation
  old_state:
    entity_id: automation.test_user_id_context_propagation
    state: "on"
    attributes:
      last_triggered: "2023-04-02T12:09:51.491295+00:00"
      mode: queued
      current: 0
      max: 10
      id: "1680437279897"
      friendly_name: Test User_id Context propagation
    last_changed: "2023-04-02T12:09:43.011790+00:00"
    last_updated: "2023-04-02T12:09:51.494039+00:00"
    context:
      id: 01GX0XZC43TVA1Z5919QWG7SQS
      parent_id: 01GX0XZC42ED9VN8XHEXBCHCRM
      user_id: null
  new_state:
    entity_id: automation.test_user_id_context_propagation
    state: "on"
    attributes:
      last_triggered: "2023-04-02T12:22:54.218899+00:00"
      mode: queued
      current: 1
      max: 10
      id: "1680437279897"
      friendly_name: Test User_id Context propagation
    last_changed: "2023-04-02T12:09:43.011790+00:00"
    last_updated: "2023-04-02T12:22:54.219015+00:00"
    context:
      id: 01GX0YQ8GABC8MJF0ZGPCVK46H
      parent_id: 01GX0YQ8G85NC539YVJ9FHRWR3
      user_id: null
origin: LOCAL
time_fired: "2023-04-02T12:22:54.219015+00:00"
context:
  id: 01GX0YQ8GABC8MJF0ZGPCVK46H
  parent_id: 01GX0YQ8G85NC539YVJ9FHRWR3
  user_id: null

Event 4

event_type: call_service
data:
  domain: input_boolean
  service: toggle
  service_data:
    entity_id:
      - input_boolean.test_bool
origin: LOCAL
time_fired: "2023-04-02T12:22:54.225416+00:00"
context:
  id: 01GX0YQ8GABC8MJF0ZGPCVK46H
  parent_id: 01GX0YQ8G85NC539YVJ9FHRWR3
  user_id: null

Event 5

event_type: state_changed
data:
  entity_id: input_boolean.test_bool
  old_state:
    entity_id: input_boolean.test_bool
    state: "on"
    attributes:
      editable: true
      friendly_name: test_bool
    last_changed: "2023-04-02T12:20:52.564858+00:00"
    last_updated: "2023-04-02T12:20:52.564858+00:00"
    context:
      id: 01GX0YKHPJDC14AD9NWYPQSHMC
      parent_id: null
      user_id: d14c52a5cc114da28fa782cb6e010299
  new_state:
    entity_id: input_boolean.test_bool
    state: "off"
    attributes:
      editable: true
      friendly_name: test_bool
    last_changed: "2023-04-02T12:22:54.227128+00:00"
    last_updated: "2023-04-02T12:22:54.227128+00:00"
    context:
      id: 01GX0YQ8GABC8MJF0ZGPCVK46H
      parent_id: 01GX0YQ8G85NC539YVJ9FHRWR3
      user_id: null
origin: LOCAL
time_fired: "2023-04-02T12:22:54.227128+00:00"
context:
  id: 01GX0YQ8GABC8MJF0ZGPCVK46H
  parent_id: 01GX0YQ8G85NC539YVJ9FHRWR3
  user_id: null

Event 6

event_type: state_changed
data:
  entity_id: automation.test_user_id_context_propagation
  old_state:
    entity_id: automation.test_user_id_context_propagation
    state: "on"
    attributes:
      last_triggered: "2023-04-02T12:22:54.218899+00:00"
      mode: queued
      current: 1
      max: 10
      id: "1680437279897"
      friendly_name: Test User_id Context propagation
    last_changed: "2023-04-02T12:09:43.011790+00:00"
    last_updated: "2023-04-02T12:22:54.219015+00:00"
    context:
      id: 01GX0YQ8GABC8MJF0ZGPCVK46H
      parent_id: 01GX0YQ8G85NC539YVJ9FHRWR3
      user_id: null
  new_state:
    entity_id: automation.test_user_id_context_propagation
    state: "on"
    attributes:
      last_triggered: "2023-04-02T12:22:54.218899+00:00"
      mode: queued
      current: 0
      max: 10
      id: "1680437279897"
      friendly_name: Test User_id Context propagation
    last_changed: "2023-04-02T12:09:43.011790+00:00"
    last_updated: "2023-04-02T12:22:54.231059+00:00"
    context:
      id: 01GX0YQ8GABC8MJF0ZGPCVK46H
      parent_id: 01GX0YQ8G85NC539YVJ9FHRWR3
      user_id: null
origin: LOCAL
time_fired: "2023-04-02T12:22:54.231059+00:00"
context:
  id: 01GX0YQ8GABC8MJF0ZGPCVK46H
  parent_id: 01GX0YQ8G85NC539YVJ9FHRWR3
  user_id: null
@Xyaren Xyaren changed the title Context User_Id ist not propagated when an automation is triggered by an Mobile App event. Context User_Id ist not propagated when an automation is triggered by an MobileApp event. Apr 2, 2023
@Xyaren Xyaren changed the title Context User_Id ist not propagated when an automation is triggered by an MobileApp event. Context User_Id ist not propagated when an automation is triggered by a MobileApp event. Apr 2, 2023
@Xyaren Xyaren changed the title Context User_Id ist not propagated when an automation is triggered by a MobileApp event. Context user_id ist not propagated when an automation is triggered by a MobileApp event. Apr 2, 2023
@Xyaren
Copy link
Contributor Author

Xyaren commented Apr 2, 2023

This line could be related to the issue:

trigger_context = Context(parent_id=parent_id)

This behaviour could be intentional, in that case, the logbook UI could be extended to resolve the parent context(s?) and corresponding user_id.

I could also imagine that this should be configurable on a per-trigger basis or cofigurable per automation.

@Xyaren
Copy link
Contributor Author

Xyaren commented Apr 10, 2023

Related: #16415

@Xyaren Xyaren linked a pull request Apr 10, 2023 that will close this issue
3 tasks
@Xyaren Xyaren removed a link to a pull request Apr 10, 2023
3 tasks
@issue-triage-workflows
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@Xyaren
Copy link
Contributor Author

Xyaren commented Jul 9, 2023

Still an issue.

@home-assistant
Copy link

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (automation) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of automation can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign automation Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


automation documentation
automation source
(message by IssueLinks)

@issue-triage-workflows
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@Xyaren
Copy link
Contributor Author

Xyaren commented Oct 16, 2023

Still an issue.

@issue-triage-workflows
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@Xyaren
Copy link
Contributor Author

Xyaren commented Jan 15, 2024

Still an issue.

@issue-triage-workflows
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@Xyaren
Copy link
Contributor Author

Xyaren commented Apr 15, 2024

Still an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants