Announcement

Collapse
No announcement yet.

mcsMQTT and insteon2MQTT questions

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

  • mcsMQTT and insteon2MQTT questions

    I am trying to use the mcsMQTT plugin to work with insteon2mqtt and Home Assistant. I have a couple of questions.

    Click image for larger version

Name:	dim.PNG
Views:	69
Size:	14.7 KB
ID:	1308680

    I would like to publish the state="ON" when the value is 1 to 100 and "OFF" when value=0.

    The subscribed brightness value received is 0 to 255. I am trying to use the expression field to scale the control payload value but it doesn't appear to be scaled.

    Click image for larger version

Name:	subscribe.PNG
Views:	83
Size:	15.9 KB
ID:	1308679

    Thanks,
    Patrick

  • #2
    Just curious. Is that what you use ? https://github.com/TD22057/insteon-mqtt

    Comment


    • #3
      Yes that is what I use.

      Comment


      • #4
        I did a test case using the same expression you used and provided a payload input of 100 and the result was 39.215686274509807 which looks correct to me. It may be the case that the CAPI control for your insteon device is expecting only integer values. To make the result an integer you could use the "round" function such as
        ROUND(($$PAYLOAD:/255)*100,0) in which case the 100 input would be used for CAPI control as 39.

        I also see your publish template is always "ON". If you want to handle both On and Off then you should be able to use "$$STATUS:" rather than "ON". The potential issue I see with this is that in HS the On and Off were defined as mixed case while your ON is upper case. If your subscriber is case sensitive then this will not work.

        It is also unlikely that you want string, value and log as the trigger to publish a message. Likely you will want only value since this device looks to operate solely on DeviceValue.

        Comment


        • #5
          Hi,
          I put the hard string "ON" into the publish template as a place holder. I initially tried to use $$STATUS: but it was returning the value:

          patrick@MITX-6930:~$ mosquitto_sub -h 192.168.1.6 -t "insteon/#" -v
          insteon/0b.76.db/state {"state":"20%", "brightness": 20"}

          I tried using the round function and it did not appear to be scaling based on the slider position in Home Assistant and the device control values in the log:

          patrick@MITX-6930:~$ mosquitto_sub -h 192.168.1.6 -t "insteon/#" -v
          insteon/0b.76.db/state {"state":"20%", "brightness": 20"}
          insteon/0b.76.db/level {"state": "ON", "brightness": 1}
          insteon/0b.76.db/state {"state":"1%", "brightness": 1"}
          insteon/0b.76.db/level {"state": "ON", "brightness": 15}
          insteon/0b.76.db/state {"state":"15%", "brightness": 15"}
          insteon/0b.76.db/level {"state": "ON", "brightness": 29}
          insteon/0b.76.db/state {"state":"29%", "brightness": 29"}
          insteon/0b.76.db/level {"state": "ON", "brightness": 43}
          insteon/0b.76.db/state {"state":"43%", "brightness": 43"}
          insteon/0b.76.db/level {"state": "ON", "brightness": 57}
          insteon/0b.76.db/state {"state":"57%", "brightness": 57"}
          insteon/0b.76.db/level {"state": "ON", "brightness": 75}
          insteon/0b.76.db/state {"state":"75%", "brightness": 75"}
          insteon/0b.76.db/level {"state": "ON", "brightness": 95}
          insteon/0b.76.db/state {"state":"95%", "brightness": 95"}
          insteon/0b.76.db/level {"state": "ON", "brightness": 110}
          insteon/0b.76.db/state {"state":"1%", "brightness": 1"}
          Click image for larger version  Name:	dim.PNG Views:	0 Size:	24.5 KB ID:	1308789

          Comment


          • #6
            I can see where the status for the dim values is the % of dim rather than ON/OFF. That makes sense, albeit not what you want.

            mcsMQTT uses the subscribed payload to search for CAPI control values to send to HS. It uses the event callback to publish. If I recall correctly the debug log (enabled from General Tab with file in \data\mcsMQTT) will contain more detail on both of these transactions. If you can post that file then that should help understand.

            Comment


            • #7
              For the round function, this is what I am using for the regex expression: /^[0-9]*$/

              I uploaded a snippet of the log file. log_file.txt

              Comment


              • #8
                As best as I can tell you sent a brightness level 165 to HS and no numeric expression was applied. HS did not have a CAPI value of 165. This does confirm that it is only looking for integer values so rounding is needed. The rounding is done as part of the numeric expression as I posted above. The regular expression is applied before numeric expressions are evaluated so attempting to do a round with RegEx will not work.

                I did not fully trace the code, but it looks like the DeviceString was updated which has no effect on the DeviceValue which is what is used for the control aspects.

                Have you tried the numeric expression I posted above? It seems now there is no numeric expression being applied. The expression information is contained in \data\mcsMQTT\mcsMQTT.db if you wish me to look at it.

                Comment


                • #9
                  I did try using the rounding function with the scaling.

                  Click image for larger version

Name:	scale.PNG
Views:	51
Size:	52.8 KB
ID:	1308878

                  Comment


                  • #10
                    Here is the database file.
                    mcsMQTT.zip

                    Comment


                    • #11
                      In the database it shows numeric expressions on both insteon/0b.76.db/state:brightness and insteon/0b.76.db/level:brightness topics with rounding on the level one. The first of these must just be an artifact of a prior exercise, but should not cause any issues. I added debug shown below for each step in evaluation of a numeric expression shown below. I also included the debug that was unchanged from the CAPIControl attempts. The output will shown in the debug log. It is at http://mcsSprinklers.com/mcsMQTT_4_0_0_1.zip. Only HSPI_MCSMQTT.exe changed.

                      Code:
                                              'control attempt of a non-plugin device
                                              Dim oTransform As Transform = oMQTT.Transform
                                              If gDebugLog Then
                                                  hsWritelog(PLUGIN_DEBUG, "Non-plugin Update Expression " & oTransform.Expression & " on payload " & oMQTT.Payload)
                                              End If
                      
                                              If oTransform.Expression <> "" Then
                                                  Dim ev As Eval3.Evaluator
                                                  ev = New Eval3.Evaluator
                                                  ev.AddEnvironmentFunctions(New EvalFunctions)
                                                  Dim lCode As Eval3.opCode = Nothing
                                                  Dim sExpression As String = ExpandedPayload(oTransform.Expression, oMQTT)
                                                  lCode = ev.Parse(sExpression)
                                                  Dim res As Object = lCode.value
                                                  If res Is Nothing Then
                                                      hsWritelog(PLUGIN_DEBUG, "Expression " & oTransform.Expression & " does not evaluate with input " & sExpression)
                                                  Else
                                                      sValue = res.ToString
                                                      If gDebugLog Then
                                                          hsWritelog(PLUGIN_DEBUG, "Substituted Payload " & sExpression & ", Expression Result " & sValue)
                                                      End If
                                                  End If
                                              End If
                      
                                              Dim arrB() As Boolean = CAPIControl(iRef, sValue, nValue)
                                              bFound = arrB(0)
                                              bValueChange = arrB(1)
                                              nNewValue = dv.devValue(Nothing) '2/21/2019 from hs to nothing
                                              If Not bFound Then
                                                  hsWritelog(PLUGIN_NAME, "Unable to find CAPI control " & sValue & " for device " & iRef.ToString)
                                              Else
                                                  bValueChange = bValueChange Or (nNewValue <> nHSValue)
                                              End If
                      Code:
                          Public Function CAPIControl(ByVal iRef As Integer, ByVal sValue As String, ByVal nValue As Double) As Boolean()
                              Dim bFound As Boolean = False
                              Dim sValueUC As String
                              Dim bValueChange As Boolean = False
                              If sValue <> "" Then
                                  sValueUC = sValue.ToUpper
                              Else
                                  sValueUC = ""
                              End If
                      
                              Dim arrCAPI As CAPIControl() = hs.CAPIGetControl(iRef)
                              If gDebugLog Then
                                  hsWritelog(PLUGIN_DEBUG, "Command nonPlugin Device " & iRef.ToString & " to " & sValue)
                              End If
                              For Each oCAPI As CAPIControl In arrCAPI
                                  If oCAPI IsNot Nothing Then
                                      If gDebugLog Then
                                          Dim sRange As String = "Nothing"
                                          If oCAPI.Range IsNot Nothing Then
                                              sRange = oCAPI.Range.RangeStart.ToString & " to " & oCAPI.Range.RangeEnd.ToString
                                          End If
                                          'If gDebugLog Then
                                          hsWritelog(PLUGIN_DEBUG, "Command " & iRef.ToString & " to " & sValue & ", nValue=" & nValue.ToString & ", ControlValue=" & oCAPI.ControlValue.ToString & ", Range=" & sRange & _
                                              ", ControlType=" & oCAPI.ControlType.ToString & ", ControlString=" & oCAPI.ControlString & ", Label=" & oCAPI.Label & ", ControlUse=" & oCAPI.ControlUse.ToString)
                                          'End If
                                      End If
                                      If IsNumeric(sValue) Then
                                          If nValue = oCAPI.ControlValue Then
                                              hs.CAPIControlHandler(oCAPI)
                                              bFound = True
                                              Exit For
                                          ElseIf oCAPI.Range IsNot Nothing Then
                                              If oCAPI.Range.RangeStart <= nValue AndAlso oCAPI.Range.RangeEnd >= nValue Then
                                                  bFound = True
                                                  hs.CAPIControlHandler(oCAPI)
                                                  Exit For
                                              End If
                                          End If
                                          If gDebugLog Then
                                              hsWritelog(PLUGIN_DEBUG, "Command numeric, but no CAPI matches value or range")
                                          End If
                                      Else
                                          If oCAPI.Label.ToUpper = sValueUC Then
                                              bFound = True
                                              hs.CAPIControlHandler(oCAPI)
                                              Exit For
                                          ElseIf oCAPI.ControlString IsNot Nothing AndAlso oCAPI.ControlString.ToUpper = sValueUC Then
                                              bFound = True
                                              hs.CAPIControlHandler(oCAPI)
                                              bValueChange = True
                                              Exit For
                                          End If
                                      End If
                                  End If
                              Next
                              If Not bFound Then
                                  For Each oCAPI As CAPIControl In arrCAPI
                                      If oCAPI IsNot Nothing Then
                                          If IsNumeric(sValue) Then
                                              If (oCAPI.ControlType = Enums.CAPIControlType.TextBox_Number OrElse oCAPI.ControlType = Enums.CAPIControlType.TextBox_String OrElse oCAPI.ControlType = Enums.CAPIControlType.Values OrElse oCAPI.ControlType = Enums.CAPIControlType.ValuesRange OrElse oCAPI.ControlType = Enums.CAPIControlType.ValuesRangeSlider OrElse oCAPI.ControlType = Enums.CAPIControlType.Radio_Option) Then
                                                  bFound = True
                                                  hs.CAPIControlHandler(oCAPI)
                                                  Exit For
                                              End If
                                          Else
                                              If (oCAPI.ControlType = Enums.CAPIControlType.TextBox_String OrElse oCAPI.ControlType = Enums.CAPIControlType.Single_Text_from_List OrElse oCAPI.ControlType = Enums.CAPIControlType.Single_Text_from_List OrElse oCAPI.ControlType = Enums.CAPIControlType.TextList) Then
                                                  bFound = True
                                                  hs.CAPIControlHandler(oCAPI)
                                                  bValueChange = True
                                                  Exit For
                                              End If
                                          End If
                                          If gDebugLog Then
                                              hsWritelog(PLUGIN_DEBUG, "Command with CAPI control not text or number box")
                                          End If
                                      End If
                                  Next
                              End If
                              Return {bFound, bValueChange}
                          End Function

                      Comment


                      • #12
                        Thanks Michael,
                        I'll give it try tonight.

                        Comment


                        • #13
                          Hi Michael,
                          I shut down HS and copied HSPI_MCSMQTT.exe and HSPI_MCSMQTT.exe.config into the /HomeSeer HS3 directory and restarted. I generated some MQTT traffic but I don't see the log file in the /data directory.

                          Comment


                          • #14
                            It is at /data/mcsMQTT/mcsMQTT Debug.txt
                            On the General Tab, the Enable General Debug checkbox should be checked.

                            Comment


                            • #15
                              I also noticed that the Payload Regex Match Pattern and Expression fields are empty now in the Edit/Add tab. I tried looking at the hs3mqtt.sqlite file and it doesn't look the same as the original file:

                              Click image for larger version

Name:	original_sql.PNG
Views:	42
Size:	19.1 KB
ID:	1309602

                              New file:

                              Click image for larger version

Name:	new_sql.PNG
Views:	44
Size:	16.8 KB
ID:	1309603


                              Click image for larger version

Name:	expression.PNG
Views:	46
Size:	52.4 KB
ID:	1309601

                              Comment

                              Working...
                              X