I have this template sensor in my setup as shown below. It uses ājqā to parse the āinsteon_devices.jsonā file into something more suited to visualize scenes and what devices are in the scenes.
In a template sensor, I do this:
- platform: command_line
scan_interval: 30
name: insteon_groups
command: "jq '{ groups: [ .[0].\"address\" as $modemaddress | .[] | .\"address\" as $device_address | select(.\"address\" != $modemaddress) | .aldb | .[] | .target=$modemaddress | { group: .\"group\", in_use: .\"in_use\", device_address: $device_address, target: .\"target\", controller: .\"controller\", brightness: .\"data1\", ramp_rate: .\"data2\", button: .\"data3\"} ] | sort_by(.group) | map(select(.\"group\" > 20)) | map(select(.in_use))}' insteon_devices.json"
value_template: "{{ now() }}"
json_attributes:
- groups
This yields a sensor that is like this:
Essentially gathering the Insteon group information together by reorganizing the JSON file that is the cache of Insteon information.
Then I have a input_select that is populated with the group numbers via an automation:
- id: '1652294634942'
alias: Set Insteon Device Groups
description: ''
trigger:
- platform: time_pattern
minutes: '1'
- platform: homeassistant
event: start
condition: []
action:
- service: input_select.set_options
data_template:
entity_id: input_select.insteon_modem_groups
options: '{{ state_attr(''sensor.insteon_groups'',''groups'') | map(attribute=''group'')
| unique | list }}
'
So I can display this:
Then on selecting a group, I can populate the devices in that group. I used two sensors but this could probaby be improved:
sensor:
# Given a group, get all the targets for that group
# This requires two pieces of information, the target address as well as the group number for multi-button, multi-outlet devices
- name: "insteon_device_groups"
state: "{{ 'OK' }}"
attributes:
in_groups: "
{% set glist = state_attr('sensor.insteon_groups','groups') %}
{% set devices = namespace(switch=[]) %}
{% for value in glist %}
{% if (value.group | int == states('input_select.insteon_modem_groups') | int) %}
{% set devices.switch = devices.switch + [(value.device_address[0:2] + '.' + value.device_address[2:-2] + '.' + value.device_address[-2:] + '_' + value.button | string) | upper] %}
{% endif %}
{% endfor %}
{{ devices.switch | unique | sort | list }}"
# Given the targets for a group, return a list of the entities
- name: insteon_group_entities
state: "{{ 'OK' }}"
attributes:
scene_entities: "
{% set gp = namespace(groups=[]) %}
{% for ent in integration_entities('insteon') %}
{% if state_attr(ent,'insteon_address') + '_' + state_attr(ent,'insteon_group') | string in state_attr('sensor.insteon_device_groups','in_groups') %}
{% set gp.groups = gp.groups + [ent] %}
{% endif %}
{% endfor %}
{{ gp.groups | unique | sort }}"
These would look like this if you look at Dev Tools:
So putting that together, I can has an input_select to choose a group number, see the devices that are in the group and their state. In my Dashboard, it looks like this:
Overall, I added features to allow adding to the scene, removing from the scene, and testing the scene with some custom buttons that run various insteon commands like scene_on, scene_off, add_all_link, etc.
For instance, if I tested group 30 āonā I would see this:
I could then select the āBack Stepsā and add that to the group through Insteon button linking OR I could use the Insteon control panel to add records for group 30 in the Hub and Back Steps entity.
I would note in that solution, I am selecting all groups (except those from the Hub) and only the groups that target the hub ā meaning not button to switch direct links unless they are in the Hub. That may not be the proper way, I am still a bit unclear on that.