Diesel Posted 20 hours ago Posted 20 hours ago (edited) Hi, @sjenkins thank you so much for the work that's gone into this plugin. Any possibility to enhance it so that virtual switches can be a scene controller rather than only a responder? Taking it a step further, also be able to create a virtual dimmer? It would solve a very fundamental and fatal issue with the way IoX considers a scene state. Edited 19 hours ago by Diesel Quote
Diesel Posted 19 hours ago Author Posted 19 hours ago from polyinterface import Node, LOGGER class VirtualSwitch(Node): """ Virtual Switch Node for PG3x that can act as a controller for a native Insteon scene. """ id = 'virtual_switch' def __init__(self, polyglot, primary, address, name, scene_id=None): super().__init__(polyglot, primary, address, name) self.scene_id = scene_id # Optional: Native Insteon scene this switch controls self.add_driver('ST', 0) # State driver: 0=off, 1=on def start(self): LOGGER.info(f"Starting Virtual Switch '{self.name}' with scene_id={self.scene_id}") # Register command handlers self.poly.on('ON', self.on_command) self.poly.on('OFF', self.off_command) def on_command(self, command=None): """Handle ON command from PG3x or scene activation""" if self.scene_id: self.send_scene_command('ON') self.set_driver('ST', 1) # Update switch state def off_command(self, command=None): """Handle OFF command""" if self.scene_id: self.send_scene_command('OFF') self.set_driver('ST', 0) def send_scene_command(self, cmd): """ Sends the ON/OFF command to the linked Insteon scene via IoX. Replace the below with actual PG3x API call to trigger a scene. """ try: LOGGER.info(f"Sending command '{cmd}' to scene {self.scene_id}") # Example pseudo-call; replace with actual API method # self.poly.iot.send_scene_command(self.scene_id, cmd) except Exception as e: LOGGER.error(f"Failed to send command to scene {self.scene_id}: {e}") def set_scene_id(self, scene_id): """Optional helper to dynamically update the controlled scene""" self.scene_id = scene_id LOGGER.info(f"Virtual Switch '{self.name}' now controls scene {scene_id}") Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.