dinki / View-Assist

View Assist provides visual feedback for the Home Assistant Assist Voice Assistant
74 stars 5 forks source link

Create core automation #17

Open dinki opened 2 weeks ago

dinki commented 2 weeks ago

View Assist core custom sentence automations should include the following:

dinki commented 2 weeks ago

This thread is for discussing and creating a core automation. @mngarchow modified one of my automations with some great additions. This will be used as the starting point for this discussion:

# Main automation configuration
alias: View Assist - Search Wikipedia
description: Search for a wikipedia article by saying who is or what is
trigger:
  - platform: conversation
    command:
      - who is {name}
      - what is [the] [a] [an] {name}
      - Tell me about [the] {name}
condition: []
action:
  - variables:
      target_satellite_device: |-
        {% for sat in expand('group.assist_satellites') %}
          {% if device_id(sat.attributes.mic_device)  == trigger.device_id %}
            {{ sat.entity_id }}
          {% endif %}
        {% endfor %}
      target_display_device: "{{ device_id(state_attr(target_satellite_device, 'display_device')) }}"
      target_mediaplayer_device: "{{ state_attr(target_satellite_device, 'mediaplayer_device') }}"
    enabled: true
  - service: rest_command.wiki_how
    response_variable: wiki_response
    enabled: true
    data:
      name: "{{ trigger.slots.name  |regex_replace(find=' ', replace='_') }}"
  - service: python_script.set_state
    data:
      entity_id: "{{ target_satellite_device }}"
      title: Wikipedia Search
  - service: python_script.set_state
    data:
      entity_id: "{{ target_satellite_device }}"
      message_font_size: 3vw
  - choose:
    - conditions:
      - condition: template
        value_template: >-
          {% if wiki_response['content']['thumbnail']['source'] != None %}true{%
          else %}false{% endif %}
      sequence:
        - service: python_script.set_state
          data:
            entity_id: "{{ target_satellite_device }}"
            image: "{{ wiki_response['content']['thumbnail']['source'] }}"
        - service: python_script.set_state
          data:
            entity_id: "{{ target_satellite_device }}"
            message: "{{ wiki_response['content']['extract'] }}"
            enabled: true
        - set_conversation_response: "{{ wiki_response['content']['extract'] }}"
          enabled: true
        - service: browser_mod.navigate
          data:
            path: /dashboard-viewassist/infopic
          target:
            device_id: "{{target_display_device}}" 
    - conditions:
      - condition: template
        value_template: >-
          {% if wiki_response['status'] != 404 %}true{%
          else %}false{% endif %}      
      sequence:
        - service: python_script.set_state
          data:
            entity_id: "{{ target_satellite_device }}"
            message: "{{ wiki_response['content']['extract'] }}"
        - set_conversation_response: "{{ wiki_response['content']['extract'] }}"
          enabled: true
        - service: browser_mod.navigate
          data:
            path: /dashboard-viewassist/info
          target:
            device_id: "{{target_display_device}}"
    default:
      - set_conversation_response: Sorry, no entry found
        enabled: true
mode: single
dinki commented 2 weeks ago

A little more on this:

Sentence is Said
Define the variables:
  target_satellite_device
  target_display_device
  target_mediaplayer_device
  target_satellite_device_type
If target_satellite_device is not None:
  Perform action to grab data to present
  If data to provide is not None:
    If target_satellite_device_type is audio only:
      Provide verbal response suitable for audio only
    else:
      Provide verbal response suitable for video display
      Provide visual response
  Else:
    Provide verbal response that no data was found/error
Else:
  Provide verbal response the target device could not be found

Tell me if you guys see any issue with this approach. I realize that some automations are simple but would like to have this framework to keep everything unified. It can be modified where needed but the approach should be consistent.