I am using this script for Insteon Keypad buttons. Insteon Keypad buttons can be linked to another Insteon device and turn that device on or off directly. HA gets a notification that the keypad button was pressed, but does not know explicitly that the other device is now “on”. The linked device does not report its state immediately to the Insteon modem.
In this case, HA is now in the state where the button is “on”, and the linked light (or lights) is “on” but HA still thinks it’s “off” (until the next poll).
However, I don’t want to simply send another “turn_on” request, since Insteon messages are serial and slow, and I don’t want to clog up the network, especially since some buttons may control 4 other lights. So this script is perfect, it allows HA to be updated to the current status without sending any messages through the Insteon component. Here is how I use it in my automation:
- alias: Kitchen Pendant Keypad Button Turned On
trigger:
platform: state
entity_id: switch.kitchen_keypad_button_2
to: 'on'
from: 'off'
condition:
condition: template
value_template: "{{ is_state('light.kitchen_pendant_lights', 'off') }}"
action:
- service: python_script.set_state
data:
entity_id: light.kitchen_pendant_lights
state: 'on'
brightness: 255