Diesel Posted August 16 Posted August 16 (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 August 16 by Diesel Quote
Diesel Posted August 16 Author Posted August 16 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
sjenkins Posted Sunday at 12:38 AM Posted Sunday at 12:38 AM @Diesel , sorry for the slow return, been a busy summer. Although the programming doesn't quite work as you have above, this is a feature which should have been added long ago. Not really sure why, I guess we all got used to using it the way we did, as a responder in a scene. Anyway, I have put it up in beta on the non-production store in v3.1.14 I will give people a while to play with it to make sure there are not any unintended consequences. 1 Quote
Diesel Posted Sunday at 01:54 PM Author Posted Sunday at 01:54 PM @sjenkins There's some really great integrations in the store, but Virtual is one of the most important. Virtual switches/dimmers as scene controller & responder solves so many issues. Thanks so much for taking the time to make this happen! 😊 1 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.