Jump to content
View in the app

A better way to browse. Learn more.

Universal Devices Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Virtual Switches as Controller in a scene?

Featured Replies

Posted

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 by Diesel

  • Author
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}")

 

@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.

 

  • Author

@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! 😊

      

 

 

 

 

 

  

Guest
This topic is now closed to further replies.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.