Announcement

Collapse
No announcement yet.

How-To: Update a virtual device with a value

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

    How-To: Update a virtual device with a value

    I have been wanting to get some basic stats into HomeSeer, mostly Temperature, CPU, etc. Here's an example on how to get a Temperature value into HomeSeer:

    Create a Virtual Device in HS. Give the Status/Graphics a range for your value. Since this is Temperature, I'm just giving it 0-100. You can always change it later:
    Click image for larger version

Name:	screenshot1.png
Views:	659
Size:	40.7 KB
ID:	1412847

    Save your Virtual Device and go into Node-Red.

    Start with an Inject Node and set the msg.payload to a JSON name/value pair:
    Click image for larger version

Name:	screenshot2.png
Views:	497
Size:	6.8 KB
ID:	1412848
    At the bottom, repeat it every 'X' interval you want - I'm doing every minute.

    Next, wire up your exec command to get your temperature and send it to a Function.
    Note the 3 dots on the exec node - make sure you wire it up to the top dot - that is for stdout, which contains the value:

    Click image for larger version

Name:	screenshot3.png
Views:	507
Size:	21.2 KB
ID:	1412849

    The function will replace that original payload from the inject and replace it with the value:
    Code:
    //Temperature comes in as temp=999.9'C
    var rawTemp = msg.payload;
    var n = rawTemp.indexOf("'");
    var wholeTemp = rawTemp.substring(5,n);
    
    //Now, put the temp into the msg payload
    
    var obj = {};
    obj['value'] = wholeTemp;
    
    msg.payload = obj;
    return msg;

    Now, wire up your HomeSeer node and select the virtual device you created above.
    Deploy your changes and that's it!
    Click image for larger version

Name:	screenshot4.png
Views:	519
Size:	30.1 KB
ID:	1412850

    This should work for any Value you want to get into HS. I havent played around with device status, but this works great.





    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

    #2
    Lovely!
    You post deserves to be up there in the stickies!


    Eman.
    TinkerLand : Life's Choices,"No One Size Fits All"

    Comment


      #3
      rmasonjr Am I correct in assuming this solution will still show unnecessary controls on the devices page for this virtual device? This has been an ongoing complaint of mine for a long time. Specifically that HS makes it hard to set a value on a "Status Only" value/status pair. From an event, this requires an immediate script statement. From the JSON API, this was not possible until early last year. From what I can tell, the current HS Node-Red nodes do not have this functionality at all. I'm at the point that I may try to patch this into the node.

      HST does not seem to understand the use case for having virtual devices to simply hold data (as you are doing). This is well supported for plugin-created devices but has been a constant struggle for user-created virtual devices.

      Comment


        #4
        No, you will get just a single "Value" button - better than an On/Off control, but still a control nonetheless...

        Click image for larger version

Name:	screenshot.png
Views:	573
Size:	20.2 KB
ID:	1413002
        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


          #5
          Yeah, that's what I was picturing. I went ahead and patched the HS Device node so that you can set a Status-Only value/status pair. I do it by setting msg.payload.statusvalue to differentiate from the existing msg.payload.value.

          You can find the code here:
          https://github.com/AZweimiller/node-...ntrib-homeseer

          Comment


            #6
            Originally posted by AZweimiller View Post
            Yeah, that's what I was picturing. I went ahead and patched the HS Device node so that you can set a Status-Only value/status pair. I do it by setting msg.payload.statusvalue to differentiate from the existing msg.payload.value.

            You can find the code here:
            https://github.com/AZweimiller/node-...ntrib-homeseer
            This should be simple, but how do I manage to get the values of a specific array in a HS device. Or not even better all arrays in separate devices at once.

            Click image for larger version

Name:	Capture- array.PNG
Views:	425
Size:	16.0 KB
ID:	1419640
            ---
            John

            Comment


              #7
              You should be able to reference the first array item with:
              Code:
              msg.payload[0]
              Another option: If you are saving the payload and can save it to an object, you would have keys which could help you keep things straight. msg is an Object and payload is a key to the msg object. Payload can be saved as an object (nested) but needs to be set as an object at some point. So if you add msg.payload.porchLight They key is porchLight in this case. And msg.payload.frontSpotlight can also be added. I set the Inject to add these 2 items using the dot notation and it worked well:

              Click image for larger version

Name:	Screenshot 2020-09-16 140629.png
Views:	443
Size:	37.8 KB
ID:	1419665



              Here is the code to import the simple flow using injecting the objects as above:
              Code:
              [{"id":"ebe02cab.a8e67","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"55d3313d.39ca2","type":"inject","z":"ebe02cab.a8e67","name":"","props":[{"p":"payload.porchLight","v":"201","vt":"num"},{"p":"payload.frontSpotlight","v":"31","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":270,"y":160,"wires":[["67c8efb4.8f916"]]},{"id":"67c8efb4.8f916","type":"debug","z":"ebe02cab.a8e67","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":480,"y":160,"wires":[]}]
              Karl S
              HS4Pro on Windows 10
              1070 Devices
              56 Z-Wave Nodes
              104 Events
              HSTouch Clients: 3 Android, 1 iOS
              Google Home: 3 Mini units, 1 Pair Audios, 2 Displays

              Comment


                #8
                Originally posted by ksum View Post
                You should be able to reference the first array item with:
                Code:
                msg.payload[0]
                Another option: If you are saving the payload and can save it to an object, you would have keys which could help you keep things straight. msg is an Object and payload is a key to the msg object. Payload can be saved as an object (nested) but needs to be set as an object at some point. So if you add msg.payload.porchLight They key is porchLight in this case. And msg.payload.frontSpotlight can also be added. I set the Inject to add these 2 items using the dot notation and it worked well:

                Click image for larger version  Name:	Screenshot 2020-09-16 140629.png Views:	0 Size:	37.8 KB ID:	1419665



                Here is the code to import the simple flow using injecting the objects as above:
                Code:
                [{"id":"ebe02cab.a8e67","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"55d3313d.39ca2","type":"inject","z":"ebe02cab.a8e67","name":"","props":[{"p":"payload.porchLight","v":"201","vt":"num"},{"p":"payload.frontSpotlight","v":"31","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":270,"y":160,"wires":[["67c8efb4.8f916"]]},{"id":"67c8efb4.8f916","type":"debug","z":"ebe02cab.a8e67","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":480,"y":160,"wires":[]}]
                Thanks, This is working.

                ---
                John

                Comment

                Working...
                X