Jump to content

Virtual Switches as Controller in a scene?


Recommended Posts

Posted (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 by Diesel
Posted
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}")

 

Posted

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

 

  • Thanks 1
Posted

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

      

 

 

 

 

 

  

  • Thanks 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing

    • No registered users viewing this page.
  • Who's Online (See full list)

    • There are no registered users currently online
  • Forum Statistics

    • Total Topics
      38k
    • Total Posts
      379.6k
×
×
  • Create New...