Switchboard without the integration
The Aivi integration sets up Switchboard and Remote buttons from a panel in Home Assistant, and presses reach Home Assistant over a connection it opens itself, with no webhook, no open port and no Home Assistant Cloud. This page is for wiring it with your own automations instead: one publishes the tiles, and a webhook automation carries out the presses.
Buttons and Toggles explains how a press travels, what a tile shows while it waits, and how an update confirms it. The steps below follow that model.
Before you start
Section titled “Before you start”- The
update_widgetRESTful command from the Home Assistant widgets guide. If you haven’t published a widget from Home Assistant yet, that guide sets it up step by step. - A widget with the Switchboard template, created in the app with the slug
living-room. - A public HTTPS address for Home Assistant on port 443, for example a Home Assistant Cloud webhook URL. See Reaching Home Assistant.
Build the switchboard
Section titled “Build the switchboard”The example publishes a switchboard with two scenes and two toggles, and turns presses into service calls.
-
Publish the switchboard whenever one of its entities changes. Every update carries the whole content, with each toggle’s
onread from its entity:- alias: "Aivi: publish the living room switchboard"triggers:- trigger: stateentity_id:- light.porch- switch.fountain- trigger: homeassistantevent: startactions:- action: rest_command.update_widgetdata:slug: living-roompayload: >-{{ {"content": {"template": "switchboard", "actions": [{"id": "movie", "label": "Movie", "icon": "tv.fill"},{"id": "all_off", "label": "All off", "icon": "power"},{"id": "porch", "label": "Porch light", "icon": "lightbulb.fill","kind": "toggle", "color": "yellow", "on": is_state("light.porch", "on")},{"id": "fountain", "label": "Fountain", "icon": "drop.fill","kind": "toggle", "color": "cyan", "on": is_state("switch.fountain", "on")}]}} | tojson }}This automation also confirms a toggle press: turning the porch light on changes its state, and the update fills in the tile. A scene changes none of these entities, so step 3 runs this automation after each scene or script to answer the button press.
-
Make a token of your own. Aivi sends it with every press, and the automation in the next step checks it, so that only Aivi can use the webhook:
openssl rand -hex 32 -
Receive presses with a webhook trigger. It checks the token, drops expired presses, then carries out the action:
- alias: "Aivi: living room switchboard presses"mode: queuedmax: 10triggers:- trigger: webhookwebhook_id: "[webhook-id]"allowed_methods: [POST]local_only: trueconditions:- condition: templatevalue_template: "{{ trigger.json.token == '[shared-secret]' }}"actions:- variables:event: "{{ trigger.json.event | from_json }}"- condition: templatevalue_template: >-{{ event.type == 'widget.action.v1'and as_timestamp(event.expires_at, 0) > as_timestamp(now()) }}- choose:- conditions: "{{ event.data.action == 'movie' }}"sequence:- action: scene.turn_ontarget: { entity_id: scene.movie }- action: automation.triggertarget: { entity_id: automation.aivi_publish_the_living_room_switchboard }- conditions: "{{ event.data.action == 'all_off' }}"sequence:- action: script.turn_ontarget: { entity_id: script.all_off }- action: automation.triggertarget: { entity_id: automation.aivi_publish_the_living_room_switchboard }- conditions: "{{ event.data.kind == 'toggle' }}"sequence:- variables:entity: >-{{ {"porch": "light.porch", "fountain": "switch.fountain"}[event.data.action] }}- if: "{{ event.data.value }}"then:- action: homeassistant.turn_ontarget: { entity_id: "{{ entity }}" }else:- action: homeassistant.turn_offtarget: { entity_id: "{{ entity }}" }The event’s fields are listed under Event types.
-
Point the widget’s webhooks at it. The
"*"entry catches every action, and thebodytemplate carries your token and the whole event:curl https://api.getaivi.app/widgets/living-room/webhooks \-X PUT \-H "Content-Type: application/json" \-H "Authorization: Token [token]" \-d '{"webhooks": {"*": {"url": "[webhook-url]", "body": {"token": "[shared-secret]", "event": "{{event_json}}"}}}}'
Reaching Home Assistant
Section titled “Reaching Home Assistant”Remote widgets and Live Activities
Section titled “Remote widgets and Live Activities”The same recipe drives a Remote
widget: publish "template": "remote" content instead. For a
Remote Live Activity, publish with a
rest_command for PATCH /activities/{slug} with "state": "ONGOING",
check for activity.action.v1 in step 3, and set the webhooks on
/activities/{slug}/webhooks in step 4.
Aivi: Live Activities and widgets over an API · Pricing · App Store