Announcement

Collapse
No announcement yet.

Controlling device based on previous status

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Controlling device based on previous status

    I am attempting to have script control and restore devices while maintaining device previous status. I have come up with the following:

    #### OfficeLightsOn.cs ####

    Code:
    public Object Main(Object[] parm) {
    
    for(int i = 1; i < 5; i++)
    {
    	string index = i.ToString();
    	string lightGlobalVariableName = "officeLamp" + index + "_ManualControlState";
    	string errCode = hs.CreateVar(lightGlobalVariableName);
    	
    	int lightState = hs.DeviceValueByName("Office Lamp " + index);
    	hs.SaveVar(lightGlobalVariableName, lightState );//+ " value is " + value.ToString()
    
    	hs.TriggerEvent ("Turn on Light" + index);
    
    }	
    
    
    return null;
    }



    Code:
    #### OfficeLightsOff.cs ####
    
    public Object Main(Object[] parm) {
    
    for(int i = 1; i < 5; i++)
    {
    	string index = i.ToString();
    	string lightGlobalVariableName = "officeLamp" + index + "_ManualControlState";
    	object lightobj = hs.GetVar(lightGlobalVariableName);
    
    	string lightState = (lightobj != null) ? lightobj.ToString():"-1";
    
    	if (lightState == "0") hs.TriggerEvent ("Turn Off Light" + index);
    }	
    return null;
    }

    Is there a better way to go about this other than defining 8 additional events? Like possibly having the trigger scripts control the devices directly. I have yet to find any examples of this. I have found examples that control what HomeSeer thinks is the device status, but it doesn't actually send command to device.

    Can someone point me in the right direction?
    Attached Files

    #2
    Been trying to figure this one out too. So far I worked around with conditional evenings like do not change the state if it is presently in this state. It would be a good feature request for hs3 that each device have a variable for previous state. This would be amazing during power outages (btw how is everyone doing that now?), home theater and accessibility

    Comment


      #3
      Originally posted by kideon View Post
      Been trying to figure this one out too. So far I worked around with conditional evenings like do not change the state if it is presently in this state. It would be a good feature request for hs3 that each device have a variable for previous state. This would be amazing during power outages (btw how is everyone doing that now?), home theater and accessibility
      hs2 saves the status to a file for use when hs2 restarts.

      hs3 must have something similar.

      I'm not sure what you guys are trying to accomplish by doing this yourself

      the other alternative is to just poll every device during startup to get the latest status. you can write a script to do this.
      Mark

      HS3 Pro 4.2.19.5
      Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
      Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
      Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

      Comment


        #4
        Imagine the 4 lamps that I am testing with are ceiling fans and the trigger is AC on, If the any of the devices are manually triggered prior to the AC coming on, I do not want the AC to shut them off when it is finished running.

        Comment


          #5
          I think I understand what you are trying to do. there are two options for saving a state of an existing device:
          1. create your own set of hs devices and set their values when necessary
          2. use the createvar and related functions.

          I would recommend option 1 as your values will be saved during a restart of hs. And you can see the values as they change so you know its working.

          to control a plugin device from a script you need to use the CAPIcontrol method. there are examples in the hs3 forum.
          Mark

          HS3 Pro 4.2.19.5
          Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway | Tuya Smart Plugs
          Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 | Ultra1Wire3 | RFXCOM | HS MyQ | BLRadar | BLDenon | Tuya | Jon00 Charting | Jon00 Links
          Platform: Windows Server 2022 Standard, i5-12600K/3.7GHz/10 core, 16GB RAM, 500GB SSD

          Comment

          Working...
          X