basnijholt / home-assistant-config

Home Assistant config files, rewritten to use the latest features, 100+ documented automations, automatically generated ToC :house: :robot:
MIT License
1.71k stars 185 forks source link

Upgrade yaml for ios after changes with 2021.05 version for HA companion #24

Open jokerigno opened 3 years ago

jokerigno commented 3 years ago

Hi,

looking at this (https://www.home-assistant.io/blog/2021/05/10/ios-20215/) automation can be simplier now.

Why don't you upgrade your configuration (it still works of course, it's just a suggestion :) )

basnijholt commented 3 years ago

Thanks a lot for the suggestion, I missed that announcement. I will take a look at it!

jokerigno commented 3 years ago

Hi,

any update? No rush of course but in the past weeks I tried to make it my self with no result.

Here's the attempt for the vacuum that of course does not work.


- alias: "Apple Watch: send vacuum cleaner"
  mode: parallel
  trigger:
    platform: event
    event_type: ios.action_fired
    event_data:
      actionName: Vacuum
  action:
  - alias: "Set up action variables"
    variables:
      # location: >
      #   # Including 'id' in 'action' allows us to identify this script run
      #   # and not accidentally trigger for other notification actions
      # soggiorno: "{{ 'soggiorno' ~ context.id }}"
      # cameradaletto: "{{ 'cameradaletto' ~ context.id }}"
      # studio: "{{ 'studio' ~ context.id }}"
      # corridoio: "{{ 'corridoio' ~ context.id }}"
      # cucina: "{{ 'cucina' ~ context.id }}"
      # casaconcordia: "{{ 'casaconcordia' ~ context.id }}"
      # zonagiorno: "{{ 'zonagiorno' ~ context.id }}"
      # zonanotte: "{{ 'zonanotte' ~ context.id }}"
      # rientrabase: "{{ 'rientrabase' ~ context.id }}"

      location: >
        {{
          {'casaconcordia': 'script.pulisci_casa_concordia',
            'cameradaletto': 'script.pulisci_camera_da_letto',
            'soggiorno': 'script.pulisci_soggiorno',
            'studio': 'script.pulisci_studio',
            'corridoio': 'script.pulisci_corridoio',
            'bagni': 'script.pulisci_bagni',
            'cucina': 'script.pulisci_cucina',
            'zonagiorno': 'script.pulisci_zona_giorno',
            'zonanotte': 'script.pulisci_zona_notte',
            'rientrabase': 'script.torna_alla_base',
          }[wait.trigger.event.data.actionName] }}

  - alias: "Send the notification"
    service: notify.mobile_app_iphone_di_marco
    data:
      message: "Inizia pulizie in?"
      data:
        actions:
          - action: "{{ soggiorno }}"
            title: "Soggiorno"
          - action: "{{ cameradaletto }}"
            title: "Camera da Letto"
          - action: "{{ studio }}"
            title: "Studio"
          - action: "{{ corridoio }}"
            title: "Corridoio"
          - action: "{{ cucina }}"
            title: "Cucina"
          - action: "{{ casaconcordia }}"
            title: "Casa Concordia"
          - action: "{{ zonagiorno }}"
            title: "Zona Giorno"
          - action: "{{ zonanotte }}"
            title: "Zona Notte"
          - action: "{{ rientrabase }}"
            title: "Rientra alla Base"
  - alias: "Wait for a response"
    wait_for_trigger:
      # We wait for specific actions because we don't want to run for
      # any action, only for a response to the one we just sent
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ soggiorno }}"
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ cameradaletto }}"
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ studio }}"
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ corridoio }}"
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ cucina }}"
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ casaconcordia }}"
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ zonagiorno }}"
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ zonanotte }}"
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ rientrabase }}"
  - alias: "Handle the response"
  - variables:
      location: >
        {{
          {'CASA_CONCORDIA': 'script.pulisci_casa_concordia',
            'CAMERA_DA_LETTO': 'script.pulisci_camera_da_letto',
            'SOGGIORNO': 'script.pulisci_soggiorno',
            'STUDIO': 'script.pulisci_studio',
            'CORRIDOIO': 'script.pulisci_corridoio',
            'BAGNI': 'script.pulisci_bagni',
            'CUCINA': 'script.pulisci_cucina',
            'ZONA_GIORNO': 'script.pulisci_zona_giorno',
            'ZONA_NOTTE': 'script.pulisci_zona_notte',
            'STOP': 'script.torna_alla_base',
          }[wait.trigger.event.data.actionName] }}
  - service: script.turn_on
    data:
      entity_id: "{{ location }}"