Announcement

Collapse
No announcement yet.

How To: "Alexa, turn the upstairs heat on"

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How To: "Alexa, turn the upstairs heat on"

    Hello All, wanted to capture a How To based on an exercise I did recently as a new user to HS and the great HAI plugin. Maybe this will help other new users in the future.

    I'm using an OmniPro IIe with 2 OmniStat 2 thermostat's, the HomeSeer Zee 2, and a few Amazon Tap devices for Alexa.

    What I was trying to accomplish was asking Alexa one of the following things using the "Simple" Alexa API:
    1. "Alexa, Turn on the downstairs heat"
      Would modify the current Heat Setpoint to 1 degree higher than the current temp, turning the heat on.
    2. "Alexa, Turn off the downstairs heat"
      Would modify the current Heat Setpoint to 1 degree lower than the current temp, turning the heat off.
    3. "Alexa, Turn on the downstairs air conditioning"
      Would modify the current Cooling Setpoint to 1 degree lower than the current temp, turning the AC On.
    4. "Alexa, Turn off the downstairs air conditioning"
      Would modify the current Cooling Setpoint to 1 degree above than the current temp, turning the AC off.


    I also have an upstairs thermostat where I wanted the same behaviors expect with saying "upstairs" instead of "downstairs".

    Assuming you have two thermostat's one named "Upstairs Thermostat" and "Downstairs Thermostat", I first created four virtual devices called "Downstairs Heat", "Downstairs Air Conditioning", and the other two for upstairs. Used the default on/off states.



    I then created an event group in HS called "Downstairs Temperature" and created 4 events:



    Each if the 4 events were configured roughly the same:

    Code:
    IF Downstairs (Heat|Air Conditioning) had its value set to (On|Off)
    THEN "Run a Script or Script Command".


    To avoid duplicating the script with subtle changes in all 4 events, I wrote a single C# script and specified parameters. First I'll post the script in C#.

    Code:
    public Object Main(Object[] parameters) 
    {
       // Split the parameters
       string strParameters = parameters[0] as string;
       string[] tokens = strParameters.Split('|');
    
       // Put the parameters into individual variables
       bool increaseTemp = Convert.ToBoolean(tokens[0]);
       string currentTemp = tokens[1];
       string setpoint = tokens[2];
    
       // Get the current temperature
       var dv = hs.DeviceValueByName(currentTemp);
    
       // Increase or decrease the temperature per the parameter
       if (increaseTemp)
       {
          dv++;
       }
       else
       {
          dv--;
       }
    
       // Retrieve the device reference by name
       var targetDevice = hs.GetDeviceRefByName(setpoint);
    
       // Retrieve the control from the device reference
       var control = hs.CAPIGetSingleControl(targetDevice,false,"0",false,true);
    
       // Set the new target temperature
       control.ControlValue = dv;
    
       // Push the value to the physical thermostat
       hs.CAPIControlHandler(control);
    
       return null;
    }
    Note the use of the CAPI API's. This is the only way to inject the heat or cool setpoint back to the physical thermostat device.

    Then for each event calling the above script I specified the script parameters as the following:


    • Turn Off Downstairs Air Conditioning:
      True|Downstairs Temperature|Downstairs Cooling Setpoint
    • Turn Off Downstairs Heat:
      False|Downstairs Temperature|Downstairs Heating Setpoint
    • Turn On Downstairs Air Conditioning:
      False|Downstairs Temperature|Downstairs Cooling Setpoint
    • Turn On Downstairs Heat:
      True|Downstairs Temperature|Downstairs Heating Setpoint


    I repeated this same thing for the upstairs events.

    The commands perform as expected and even the first day of having them working I used it several times in response to one of the kids saying they were hot. Hopefully this helps someone else!

    Thank you to rmasonjr and sparkman for helping me out getting to this solution.
    Attached Files

    #2
    Oh wow - thanks for this writeup! Great information!
    HS4Pro on a Raspberry Pi4
    54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
    Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

    HSTouch Clients: 1 Android

    Comment

    Working...
    X