#Mushroom Chip card action - context user

19 messages · Page 1 of 1 (latest)

cedar coral
#

Hi, I am triggering an automation from the click event on a mushroom chip card. It seems the context user is null. Is there any other way I can get the user performing the button click?

sturdy anvil
#

if you're inside condition or variables before actions are executed, you must use trigger.context. If you are inside an action, you can use context. But it's probably best to always use trigger.context

cedar coral
#

that is exactly what I am using

#

action: notify.mobile_app_chris_mobile
metadata: {}
data:
title: Checking context user
message: "{{trigger.context.user_id}}"

sturdy anvil
#

If you’re just in the action section of a script that does not contain triggers, you use the base context object.

cedar coral
#

Yes, i have no trigger set, then just hit it feom the action

sturdy anvil
#

That means there’s no trigger, so you use the context object

sturdy anvil
#

@cedar coral did it work?

cedar coral
#

unfortunately no. When I check the logbook it is showing as null

#

context:
id: 01J8NFSZDN2P6EX6FX0DNBTJWC
parent_id: 01J8NFSZDMCQGZ0V5Q1T6E8481
user_id: null

sturdy anvil
#

that means there is no user_id

#

can you post the entire setup you're using?

#

the fact that it has a parent_id tells me something else is creating the context

cedar coral
#

type: custom:mushroom-chips-card
chips:

  • type: template
    entity: switch.kitchen_socket_1_relay_switch
    icon: mdi:cctv
    icon_color: |-
    {{
    'green' if states('switch.kitchen_socket_1_relay_switch') == 'on'
    }}
    content: Living
    tap_action:
    action: perform-action
    perform_action: automation.trigger
    target:
    entity_id: automation.cameras_turning_on
    data:
    skip_condition: false
    hold_action:
    action: none
    double_tap_action:
    action: none
#

And the automation:
alias: Living Room Camera ON - Request
description: ""
trigger: []
condition: []
action:

  • action: notify.mobile_app_chris_mobile
    metadata: {}
    data:
    title: Checking context user
    message: "{{ context.user_id }}"
  • if:
    • condition: template
      value_template: ""
      then: []
      enabled: false
  • action: notify.mobile_app_chris_mobile
    metadata: {}
    data:
    title: "{{ trigger.entity_id }} is requesting to turn on the cameras"
    message: Test Message
    data:
    actions:
    - action: ALLOW_CAMERAS_ON
    title: Allow
    - action: BLOCK_CAMERAS_ON
    title: Block
  • wait_for_trigger:
    • platform: event
      event_type: mobile_app_notification_action
      event_data:
      action: ALLOW_CAMERAS_ON
    • platform: event
      event_type: mobile_app_notification_action
      event_data:
      action: BLOCK_CAMERAS_ON
      timeout:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
      continue_on_timeout: false
  • if:
    • condition: template
      value_template: "{{ wait.trigger.event.data.action == 'ALLOW_CAMERAS_ON' }}"
      then:
    • action: notify.mobile_app_chris_mobile
      metadata: {}
      data:
      title: "Cameras: Allowed"
      message: cameras will now be turned on
  • if:
    • condition: template
      value_template: "{{ wait.trigger.event.data.action == 'BLOCK_CAMERAS_ON' }}"
      then:
    • action: notify.mobile_app_chris_mobile
      metadata: {}
      data:
      title: "Cameras: Blocked"
      message: cameras will NOT be turned on.
      mode: single
#

the first notify is just a test. What I want is to do a condition based on which user is requesting it

sturdy anvil
#

can you please format this properly?