Dynamic Actions with Camera .0.54

With the fix in HA 0.54 we can now send a camera stream and actions to an IOS device. A limitation of this is the actions must be the same no matter what camera stream you send.

With the below config I attempted to make a more dynamic approach. I can now send a camera stream with two generic action buttons. and HA will interpret my answer based on the entity ID and button pressed.

In the IOS conf.

ios:
  push:
    categories:
      - name: camera
        identifier: 'camera'
        actions:
          - identifier: 'ALLINONE_TRUE'
            title: 'On/True/Open/Lock'
            authenticationRequired: no
          - identifier: 'ALLINONE_FALSE'
            title: 'Off/False/Close/Unlock'
            authenticationRequired: no

To send a message I am using the following message config.

- alias: IOS -  Chicken camera actions
  trigger:
    action:
    service: notify.ios_ryans_iphone_app
    data:
      message: "What should I do with the chicken door?"
      data:
        push:
          category: 'camera'
        entity_id: camera.d239
        action_data:
          entity_id: cover.chicken_door

Finally HA listens for the event to come back into Home assistant does interprets the correct action to take.

- alias: IOS - All In one camera
  trigger:
    platform: event
    event_type: ios.notification_action_fired
  condition:
   condition: template
   value_template: "{{(trigger.event.data.actionName.split('_')[0] == 'ALLINONE')}}"
  action:
    - service_template: >-
        {% set domain = (trigger.event.data['action_data']['entity_id'].split('.')[0]) %}
        {% set function = (trigger.event.data.actionName.split('_')[1]) %}
        {% set entity_id = (trigger.event.data['action_data']['entity_id']) %}
        {% if (function == 'TRUE') -%}
          {% if (domain == 'cover') -%}
            cover.open_cover
          {% elif (domain in ['light', 'switch', 'script', 'automation', 'input_boolean', 'group']) -%}
            homeassistant.turn_on
          {% elif (domain == 'lock') -%}
            lock.lock
          {% else -%}
          Invalid Domain:{{domain}} Function: {{function}} or entity:{{entity_id}}
          {% endif -%}
        {% elif (function == 'FALSE') -%}
          {% if (domain == 'cover') -%}
            cover.close_cover
          {% elif (domain in ['light', 'switch', 'script', 'automation', 'input_boolean', 'group']) -%}
            homeassistant.turn_off
          {% elif (domain == 'lock') -%}
            lock.unlock
          {% else -%}
          Invalid Domain:{{domain}} Function: {{function}} or entity:{{entity_id}}
          {% endif -%}
        {% else -%}
        Invalid Domain:{{domain}} Function: {{function}} or entity:{{entity_id}}
        {% endif -%}
      data_template:
       entity_id: "{{trigger.event.data['action_data']['entity_id']}}"

3 Likes

@rabittn
I can’t get this to work, can you help me please?

ios:
  push:
    categories:
      - name: camera
        identifier: 'camera'
        actions:
          - identifier: 'ALLINONE_TRUE'
            title: 'On/True/Open/Lock'
            activationMode: 'foreground'
            authenticationRequired: no
            destructive: yes
            # behavior: 'default'
          - identifier: 'ALLINONE_FALSE'
            title: 'Off/False/Close/Unlock'
            activationMode: 'foreground'
            authenticationRequired: no
            # destructive: yes
            # behavior: 'default'

ios_alarm_notification.yaml

alias: "Beweging in den hof"
trigger:
  platform: state
  entity_id: binary_sensor.den_hof_outdoor_human
  to: 'on'
condition:
  condition: or
  conditions:
    - condition: state
      entity_id: alarm_control_panel.ha_alarm
      state: 'armed_away'
    - condition: state
      entity_id: alarm_control_panel.ha_alarm
      state: 'armed_home'
action:
  - service: notify.ios
    data:
      message: "Bezoek! -- Alarm opzetten?"
      data:
        push:
          badge: 0
          category: 'camera'
        entity_id: camera.den_hof
        action_data:
          entity_id: input_boolean.alarm_test

ios_action.yaml

alias: IOS - All In one camera
trigger:
  platform: event
  event_type: ios.notification_action_fired
condition:
  condition: template
  value_template: "{{(trigger.event.data.actionName.split('_')[0] == 'ALLINONE')}}"
action:
  - service_template: >-
      {% set domain = (trigger.event.data['action_data']['entity_id'].split('.')[0]) %}
      {% set function = (trigger.event.data.actionName.split('_')[1]) %}
      {% set entity_id = (trigger.event.data['action_data']['entity_id']) %}
      {% if (function == 'TRUE') -%}
        {% if (domain == 'cover') -%}
          cover.open_cover
        {% elif (domain in ['light', 'switch', 'script', 'automation', 'input_boolean', 'group']) -%}
          homeassistant.turn_on
        {% elif (domain == 'lock') -%}
          lock.lock
        {% else -%}
        Invalid Domain:{{domain}} Function: {{function}} or entity:{{entity_id}}
        {% endif -%}
      {% elif (function == 'FALSE') -%}
        {% if (domain == 'cover') -%}
          cover.close_cover
        {% elif (domain in ['light', 'switch', 'script', 'automation', 'input_boolean', 'group']) -%}
          homeassistant.turn_off
        {% elif (domain == 'lock') -%}
          lock.unlock
        {% else -%}
        Invalid Domain:{{domain}} Function: {{function}} or entity:{{entity_id}}
        {% endif -%}
      {% else -%}
      Invalid Domain:{{domain}} Function: {{function}} or entity:{{entity_id}}
      {% endif -%}
    data_template:
       entity_id: "{{trigger.event.data['action_data']['entity_id']}}"

Looks like you are just missing the action buttons from the message? is that correct?

That’s correct

Have you updated the push configs in the ios app?

1 Like

:+1:t2::+1:t2::+1:t2::+1:t2::+1:t2::+1:t2::+1:t2::+1:t2::+1:t2::+1:t2:

HI, been a long while
I want to try and use it to switch on an espresso machine, and don’t use cameras, but like to try proximity as trigger.
hence i renamed the iOS and automation like this, would that be ok (for starters, figure out the trigger of proximity later on…)?

- alias: IOS - Espresso actions
  trigger:
  action:
    service: notify.ios_telefoonmhb
    data:
      message: 'Wil je vast de Espresso aanzetten?'
      data:
        push:
          category: 'espresso'
          entity_id: /local/activities/origineel/opstaan.png
        action_data:
          entity_id: switch.sw_espresso_keuken_template

and

push:
  categories:
    - name: Espresso
      identifier: 'espresso'
      actions:
        - identifier: 'ALLINONE_TRUE'
          title: 'Yes/On/True/Open/Lock'
          authenticationRequired: no
        - identifier: 'ALLINONE_FALSE'
          title: 'No/Off/False/Close/Unlock'
          authenticationRequired: no

al, that is happening now is the message on my phone, whithout any buttons with actions. (yes, i did update the push notifications in the app)
Also, Somehow I cant enable this automation. it switches back to off whenever I switch it on. I can trigger it in the dev-service tools.
maybe thats because there’s no trigger (yet)?

I do not see a trigger in your automation

no I only posted the action bit…

the triggers are good, its the fact I cant get the buttons to show up on the phone.

Even when I trigger manually, only the message is displayed.

guess i found it: had to hold/push on my iPhone to see the actionable buttons> hadn’t read about that, and thought it would show up with the message notification itself…

anyt thoughts on how to get a local image file to show up in the action_data: ?

image: /local/activities/espresso.png ?