Announcement

Collapse
No announcement yet.

Custom device for communication back and forth between Homeseer and Hubitat

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

    Custom device for communication back and forth between Homeseer and Hubitat

    I setup a custom device in Hubitat to make it easy to pass basic information back and forth between Homeseer. I got the device driver from the guys at sharptools. I will add it at the end in case anyone else wants to use it. The idea is that I can setup devices to pass information back and forth easily that are note related to a particular device. The example below is for keeping track of the number of people home as tracked in Homeseer through mobile phone location.

    The plugin has a hard time understanding the deice, for obvious reasons, so Would it be possible to add this as a supported device? Thanks.

    This is what I see in Homeseer:

    Click image for larger version

Name:	Screen Shot 2020-12-25 at 7.37.55 PM.png
Views:	393
Size:	123.3 KB
ID:	1443088

    View of device in Hubitat.




    Here is what maker shows:

    {"name":"Homeseer - People Home","label":"Homeseer - People Home","type":"Virtual Values","id":"846","date":"2020-12-25T12:51:00+0000","model":null,"manufacturer":null,"capabili ties":["Actuator","Notification","SwitchLevel","Switch","Sensor","S peechSynthesis"],"attributes":{"switch":"on","dataType":"NUMBER","values":nu ll,"text":"Here is the text","level":"100","number":"99"},"commands":[{"command":"deviceNotification"},{"command":"setNumber"},{"c ommand":"setLevel"},{"command":"speak"},{"command":"setText" },{"command":"off"},{"command":"on"}]}

    Driver code:

    Code:
    /* Virtual Values Author: @josh (SharpTools.io) Description: The Virtual Values device driver exposes a variety of methods which can be used to set values of specific attributes. These attributes can then be used in other Apps within Hubitat or in SharpTools.io Dashboards by using Hero Attribute tiles. This serves as a flexible 'utility' device for setting arbitrary values that you want to use elsewhere. Command to Attribute Mappings setText → text speak → text *1 deviceNotification → text *2 setNumber → number setLevel → level, [switch] *3 on → switch off → switch *1 speak() is a wrapper method for setText to provide compatibility with apps that support Speech Synthesis devices *2 deviceNotification() is a wrapper method for setText to provide compatibility with apps that support Notify devices *3 setLevel will issue the off() command if the level is set to 0 and will leave the level set at the previous value Other Notes: The on/off commands are useful for reflecting an active/default state in SharpTools.io dashboards which is helpful for setting the color of your tile based on the device's state. */ metadata { definition (name: "Virtual Values", namespace: "sharptools-io", author: "Josh Lyon") { capability "Actuator" capability "Sensor" capability "Switch" capability "Switch Level" capability "Notification" capability "Speech Synthesis" command "setText", ["STRING"] command "setNumber", ["NUMBER"] attribute "text", "STRING" attribute "number", "NUMBER" } preferences {} } def parse(String description) { } def on() { log.trace "Executing 'on'" turnOn() } def off() { log.trace "Executing 'off'" turnOff() } def setNumber(value){ log.trace "Executing setNumber $value" Map numberEvent = buildEvent("number", value, null) sendEvent(numberEvent) } def setText(value){ log.trace "Executing setText $value" Map event = buildEvent("text", value, null) sendEvent(event) } /* Also map speak() and deviceNotification() to setText for convenience */ def speak(value){ setText(value) } def deviceNotification(value){ setText(value) } private Map buildEvent(name, value, unit=null) { Map eventMap = [name: name, value: value, unit: unit, isStateChange: true] return eventMap } /*----- Set Level ---- */ def setLevel(value) { log.trace "Executing setLevel $value" def intValue = value as Integer def newLevel = Math.max(Math.min(intValue, 100), 0) Map levelEventMap = buildEvent("level", newLevel, "%") if (levelEventMap.value == 0) { turnOff() // notice that we don't set the level to 0' } else { implicitOn() sendEvent(levelEventMap) } } def setLevel(value, duration) { log.trace "Executing setLevel $value (ignoring duration)" setLevel(value) } private implicitOn() { if (device.currentValue("switch") != "on") { turnOn() } } private turnOn() { sendEvent(name: "switch", value: "on", isStateChange: true) } private turnOff() { sendEvent(name: "switch", value: "off", isStateChange: true) } def installed() { setLevel(100) setText("Use setText to set me") setNumber(100) }

    #2
    The plugin keys off of the advertised capabilities so that is what you are seeing in HS. What are you not getting that you want?
    "capabili ties":["Actuator","Notification","SwitchLevel","Switch","Sensor ","S peechSynthesis"]

    Comment


      #3
      I am just figuring out how to work with custom drivers. I don't fully understand what maker is reporting in the capabilities and how that maps to the driver.

      But, when it creates the devices in Homeseer these work:

      Say - Updates the Speak element in Hubitat (SpeechSynthesis)
      Switch - Updates the Switch element in Hubitat

      These are created but don't work:

      track - is that connected to the Notification? I would assume that would update the device notification element in Hubitat and ultimately the text variable but nothing happens.
      switchlevel - no response either way

      And I am not sure what these map to in hubitat but are not doing anything that I can see:
      ramprate
      status
      track - is this track title as in audio track?
      wave light

      What I am trying to get to is a set of fairly generic capabilities

      on/off
      level and duration
      three methods for sending text - Notification, Speak, Generic - they all bind to the same text value. The driver breaks them out for 1) speak() a wrapper method for setText to provide compatibility with apps that support Speech Synthesis devices, 2) deviceNotification() a wrapper method for setText to provide compatibility with apps that support Notify devices, and 3) a generic text field
      number - ability to send a numeric value back and forth

      Hopefully that makes sense? Thanks.




      Comment


        #4
        track - is that connected to the Notification? I would assume that would update the device notification element in Hubitat and ultimately the text variable but nothing happens.
        track is created from the SpeechSynthesis capability which what first added with Chromecast Video. The same is true for status

        switchlevel - no response either way

        And I am not sure what these map to in hubitat but are not doing anything that I can see:
        ramprate
        status
        track - is this track title as in audio track?
        wave light
        switchlevel is created from SwitchLevel capability. Dimmer type devices are typical for this capability. Zwave Light and RampRate are also created from switchlevel

        Switch is created from Switch capability. It is used often for two-state devices.

        Sensor capability is used for OpenWeatherMap and Xiaomi Aqara Vibration Sensor. Other special case scenarios can be added as the need arises.

        Notification and Actuator are not currently used in mcsMQTT. I do not know if it is because these capabilities were never reported by Maker or if they were redundant in the list of capabilities for a device so not used. For example, a device could report Switch and Actuator capability and mcsMQTT will only create one device for the switch and ignore that a switch is a type of actuator.

        [quote]
        What I am trying to get to is a set of fairly generic capabilities

        on/off
        level and duration
        [quote]

        I believe you already have on/off with Switch, level and duration with SwitchLevel and RampRate

        three methods for sending text - Notification, Speak, Generic - they all bind to the same text value. The driver breaks them out for 1) speak() a wrapper method for setText to provide compatibility with apps that support Speech Synthesis devices, 2) deviceNotification() a wrapper method for setText to provide compatibility with apps that support Notify devices, and 3) a generic text field
        number - ability to send a numeric value back and forth
        I am not understanding what you are asking for in HS
        The commands that are available are underscored from the Maker disclosure posted above.
        [{"command":"deviceNotification"},{"command":"setNumber"}, {"c ommand":"setLevel"},{"command":"speak"},{"command":"setText" },{"command":"off"},{"command":"on"}]}

        mcsMQTT will have one command associated with a device. speak is associated with SpeechSynthesis/say. On and Off and setLevel are used by Switch and SwitchLevel

        This leaves deviceNotification, setText and setNumber which are not currently associated with a capability. It is possible to use the Notification capability and create three HS devices for these. What would also be needed is what is reported back by Maker when the Hubitat endpoint changes for each of the three so the plugin knows how to update the HS device as status changes. This information is in the mcsHubitat debug when the status from Hubitat changes. Also needed are the command parameters or acceptable values for deviceNotification command. My guess however, is that deviceNotification and setNumber will not be used because setText will be the only thing that HS will be able to do based upon a change in the DeviceString of the HS device.

        I do not understand what you mean by a wrapper method or binding to the same text value. mcsHubitat establishes a one-to-one relationship between an end point in Hubitat and a HS Device Feature. The Hubitat driver has a different orientation so it could pipe text from setText into SpeechSynthesis to have the same effect as the speak command.

        From what I can tell is that you are asking for mcsHubitat to support a two way means of HS and Hubitat to exchange text values. There are HS devices created such as Zwave light and track that are not appropriate for this Hubitat device. They can be deleted in HS.

        Am I correct or what do I have wrong?

        Comment


          #5
          You are correct that I am trying to create a two-way generic communication method between HS and Hubitat. On the Hubitat side I am processing these changes and triggering changes on my dashboards. In most cases, communication back to Homeseer is not required as I can use the On/Off status to let Homeseer know that something has been done, etc. But having the two-way would be nice if I want to communicate something more than just on/off status as an acknowledgement.

          For deviceNotification, setText and setNumber I grabbed the debug information below, and then some examples of activating them. If it is possible to create devices for these three that would be ideal. Thanks.


          Code:
          12/27/2020 7:38:57 AM 6339 | HubitatDevice:[{"name":"SimonPhone","label":"SimonPhone","type":"Mobile App Device","id":"1","date":"2020-12-26T20:54:02+0000","model":null,"manufacturer":null,"capabili ties":["Notification","Sensor","PresenceSensor"],"attributes":{"presence":"present","dataType":"STRING","val ues":null,"notificationText":null},"commands":[{"command":"arrived"},{"command":"departed"},{"command":"dev iceNotification"}]},{"name":"Echo Speaks Device","label":"Echo - Dad's Office","type":"Echo Speaks Device","id":"385","date":"2020-12-27T12:38:29+0000","model":null,"manufacturer":null,"capabili ties":["Notification","Refresh","AudioNotification","AudioVolume"," MusicPlayer","Sensor","SpeechSynthesis"],"attributes":{"wasLastSpokenToDevice":"false","dataType":"N UMBER","values":null,"lastAnnouncement":null,"lastSpokenToTi me":"1600891417035","lastCmdSentDt":"Thu Aug 27 16:19:25 EDT 2020","trackData":null,"doNotDisturb":"false","firmwareVer": "658655620","lastVoiceActivity":"alexa time to go","mute":"unmuted","followUpMode":"true","lastSpeakCmd":"H i Ganesh","status":"stopped","onlineStatus":"online","volume": "60","supportedMusic":", Amazon Music, My Library, SiriusXM, Spotify, TuneIn, iHeartRadio","trackImageHtml":"<img src=\"\"/>","btDeviceConnected":null,"lastUpdated":"Dec 27, 2020 - 7:38:29 AM","currentStation":"Idle","deviceFamily":"ECHO","deviceSer ial":"B0F00712450401XF","audioTrackData":"{}","trackDescript ion":"SiriusXM Chill","trackImage":"https://siriusxm-priprodart.akamaized.net/images/chan/b8/ea67d7-8144-5c5f-03ec-5aedc316815b.png","permissions":"[reminders, flashBriefing, followUpMode, volumeControl, tuneInRadio, amazonMusic, spotify, alarms, bluetoothControl, announce, iHeartRadio, pandoraRadio, guardSupported, TTS, mediaPlayer, doNotDisturb, wakeWord, siriusXm, microphone, isEchoDevice]","alexaPlaylists":"{\"##\":[{\"entryList\":null,\"playlistId\":\"5163efa0-2acd-4213-a011-e2eddef07d75\",\"title\":\"##\",\"trackCount\":6,\"version\" :\"6\"}],\"$christmas\":[{\"entryList\":null,\"playlis ...

          Code:
          12/27/2020 7:39:00 AM 9621 | Message received: { "source":"DEVICE","name":"text","displayName" : "Homeseer - Generic Variable", "value" : "This is device notification", "unit":"null","deviceId":846,"hubId":0,"installedAppId":0,"descriptionText" : "null"}
          12/27/2020 7:39:02 AM 11412 | Message received: { "source":"DEVICE","name":"number","displayName" : "Homeseer - Generic Variable", "value" : "9999", "unit":"null","deviceId":846,"hubId":0,"installedAppId":0,"descriptionText" : "null"}
          12/27/2020 7:39:05 AM 14092 | Message received: { "source":"DEVICE","name":"text","displayName" : "Homeseer - Generic Variable", "value" : "This is set text", "unit":"null","deviceId":846,"hubId":0,"installedAppId":0,"descriptionText" : "null"}
          Click image for larger version

Name:	Screen Shot 2020-12-27 at 8.10.25 AM.png
Views:	251
Size:	153.9 KB
ID:	1443355

          Comment


            #6
            The setText and setNotification have the same footprint so are just two names for the same thing when viewed from the Maker interface. If Maker will send "text" update for either of the two Hubitat endpoints so they will both map into the same one text HS device.

            Let me know if 4.3.12.0 or 3.3.12.0 works as you expect

            HS4 http://mcsSprinklers.com/HSPI_mcsHubitat_4_3_12_0.zip
            HS3 http://mcsSprinklers.com/mcsHubitat_3_3_12_0.zip

            Actuator, Notification, Switch Level, Switch, Sensor and Speech Synthesis.

            These capabilities are mapped to HS devices:

            Actuator – Not mapped
            Switch Level – SwitchLevel, RampRate, Zwave Light
            Switch – Switch, Zwave Light
            Sensor – Not mapped
            Speech Synthesis – Say, Text, Number

            Any HS devices that will not be used can be deleted from HS.


            Click image for larger version

Name:	Capture.PNG
Views:	173
Size:	61.6 KB
ID:	1443441

            Comment


              #7
              Awesome. Thanks.

              Comment


                #8
                Hi Mike - I am attempting to use one of these generic variables to pass URLs to Hubitat. It seems that if I include any "/" it fails. Is it possible to include these characters when sending text? Thanks.

                http://albumart.siriusxm.com/albumar...9990-001_m.jpg

                Comment


                  #9
                  There was another thread where speakable text was being worked and the bottom line is that Maker API did not appear to make provisions for URI or escape encoding to handle characters that are part of the URL syntax.. The following list needed to be eliminated from any text that was being sent to Echo Speaks. I believe the other user tried to communicate with MakerAPI author without success.

                  string[] replaceables = new[] { "\n", "\r", "\t", "_", "&", "\", "?", "/", "," };

                  Comment


                    #10
                    Got it. Thanks. I got around it by downloading the image locally and pointing hubitat to the local file. But I will ping the maker author to see anyway?

                    Comment


                      #11
                      Mike, I am trying to set one of the elements in this device through a script. I want to set the value of device 4378. I can update it through the HS3 web interface by typing a number into the (value) field and clicking submit and it updates in Hubitat. But if I try to update it by issuing the following script command:

                      temp = hs.SetDeviceValueByRef(4378, value, True)

                      It updates in the HS3 web interface but Hubitat does not reflect the change.

                      What am I doing wrong? Thanks.

                      Click image for larger version  Name:	Screen Shot 2021-05-29 at 12.13.51 PM.png Views:	0 Size:	118.5 KB ID:	1476966

                      Comment


                        #12
                        When trying to control a device that is owned by a pluign (i.e. not a virtual device) then CAPI is used. This gets routed to the plugin and the plugin will update the HS device based upon the results of its communication with the hardware that the plugin is interfacing. An extract of what I use is shown below


                        HS4:
                        Code:
                         hs.SendControlForFeatureByValue(iRef, nValue)
                        HS3:
                        Code:
                        Sub CAPIControl(ByVal iRef As Integer, ByVal nValue As Double) 
                        Dim arrCAPI As CAPIControl() = hs.CAPIGetControl(iRef)
                        For Each oCAPI As CAPIControl In arrCAPI
                         If oCAPI IsNot Nothing Then
                          If nValue = oCAPI.ControlValue Then
                             hs.CAPIControlHandler(oCAPI)
                             Exit For
                          ElseIf oCAPI.Range IsNot Nothing Then
                            If oCAPI.Range.RangeStart <= nValue AndAlso oCAPI.Range.RangeEnd >= nValue Then
                              hs.CAPIControlHandler(oCAPI)
                              Exit For
                            End If
                          End If
                         End if
                        Next
                        End Sub

                        Comment


                          #13
                          Yikes, this is potentially getting outside of my self-taught vb skills. I poked around a little but didn't have much luck. I am using HS3. Also, I am adding this to an existing vbs script.

                          I thought to put the code in a separate file to make it easy to call:

                          temp = hs.RunScriptFunc("capi_plugin_control.vb","CAPIControl","437 8,99", FALSE, FALSE)

                          I copied the code above and put it into the file capi_plugin_control.vb.

                          I tried multiple ways to do this but no luck. Again - self-taught on vb but googling didn't help on this one. Any thoughts? Thanks.

                          Comment


                            #14
                            Take a look at setdevicevaluebyref and set string wont affect the actual physical device - HomeSeer Message Board This is the same thing you are trying to do.

                            Comment


                              #15
                              I actually started by looking in TenScriptAid but couldn't see any CAPI ControlUse. See below the screenshot looking at the 4378 device. Normally I would look there, copy the code and then insert it into my script.

                              In the thread someone made a comment "Does the device you are referencing have ControUse defined? Not all plugin authors do such." Assuming this is true, is it possible that ControlUse is not defined for this device? Thanks.

                              Click image for larger version

Name:	Screen Shot 2021-05-29 at 4.04.51 PM.png
Views:	48
Size:	333.0 KB
ID:	1477007

                              Comment

                              Working...
                              X