No announcement yet.

Control Non-Plugin Device - Payload Replace?

  • Filter
  • Time
  • Show
Clear All
new posts

    Control Non-Plugin Device - Payload Replace?

    I've been looking for a while and haven't found the answer to what is likely a pretty basic question.

    I've created a Non-Plugin HS device and it will be controlled by an MQTT payload that sends either "on" or "off" (without quotes). mcsMQTT is receiving the payload, I just need to convert it to a Device control.

    My HS device has control values of 0 and 100. The device Status I'm using is "open" and "closed" (not "on" and "off").

    Topic :: Payload
    automation/arduino_01/binary_sensor/I8 :: on

    How can I use mscMQTT to set the device to 0 for a payload of "off" and to 100 for a payload of "on"? I'm assuming that I'd use the "Payload RegEx Match Pattern" and "Payload RegEx Replace Pattern", but have no idea what that would look like.

    Thanks for any help you can provide.


    Normally the actuating device defines the parameters of control. In your case this is something that has VSP definition of 0=closed and 100=open. This means that you need to provide a payload of closed/open or 0/100 to control this device. Since your want the payload to be off/on there needs to be a transformation. RegEx is likely one way it could be done. I find RegEx hard so I typically do not use it and when I do I do google search to try to find the expression I need.

    What I would do is use the Expression function Replace. It should be the following. I did not test to confirm.


      Thanks Michael! Looking at that helps me start to make sense of it.

      I submitted the REPLACE text you suggested into the "Payload RegEx Replace Pattern" field, but it doesn't seem to work. The "Payload RegEx Replace Pattern" field shows up blank the next time I "Edit/Add" that device.

      I wonder if I might have a database problem again. I could e-mail the database to you again if you think it might be worth a look?



        This is expression text box, not the regex text box.


          Still no luck...

          REPLACE(REPLACE($$PAYLOAD:,"on","open"),"off","closed") in the Expression field: (also tried with with Closed and Open)

          3/7/2021 12:32:03 PM 176677268 | HSEvent VALUE_CHANGE| 1024| 003D3811-031-Q14| 22| 21| 107
          3/7/2021 12:32:03 PM 176677274 | HSEvent VALUE_CHANGE| 1024| 003D3811-031-Q12| 0| 255| 105
          3/7/2021 12:32:04 PM 176677290 | HSEvent VALUE_CHANGE| 1024| | 12789| 12788| 267
          3/7/2021 12:32:04 PM 176677524 | ProcessMessage New automation/arduino_01/binary_sensor/I3
          3/7/2021 12:32:04 PM 176677524 | Update Accepted 44 to on StatusType=0 Payload= on RegExValue=on
          3/7/2021 12:32:04 PM 176677528 | Non-plugin Update Expression REPLACE(REPLACE($$PAYLOAD:,"on","open"),"off","closed") on payload on
          3/7/2021 12:32:04 PM 176677531 | ActOnMessageForTrigger Topic automation/arduino_01/binary_sensor/I3,Payload=on, Triggers=0
          3/7/2021 12:32:05 PM 176678491 | HSEvent VALUE_CHANGE| 1024| | 12790| 12789| 267
          3/7/2021 12:32:06 PM 176679292 | HSEvent VALUE_CHANGE| 1024| | 12791| 12790| 267
          3/7/2021 12:32:06 PM 176679962 | HSEvent VALUE_SET| 2048| M2| 100| 100| 477
          3/7/2021 12:32:07 PM 176680493 | HSEvent VALUE_CHANGE| 1024| | 12792| 12791| 267
          3/7/2021 12:32:08 PM 176681293 | HSEvent VALUE_CHANGE| 1024| | 12793| 12792| 267
          3/7/2021 12:32:08 PM 176681671 | HSEvent VALUE_SET| 2048| 003D3811-052-Q65| 927.903| 927.903| 399
          3/7/2021 12:32:08 PM 176682028 | HSEvent VALUE_SET| 2048| M1| 100| 100| 476
          3/7/2021 12:32:08 PM 176682214 | ProcessMessage New sensor/thgn122_123_thgn132_thgr122_228_238_268_62_01_temperature
          With REPLACE(REPLACE($$PAYLOAD:,"on",100),"off",0) in the Expression field:

          3/7/2021 12:35:26 PM 176879434 | HSEvent VALUE_CHANGE| 1024| | 12991| 12990| 267
          3/7/2021 12:35:27 PM 176880634 | HSEvent VALUE_CHANGE| 1024| | 12992| 12991| 267
          3/7/2021 12:35:27 PM 176881285 | HSEvent VALUE_SET| 2048| M2| 100| 100| 477
          3/7/2021 12:35:28 PM 176881435 | HSEvent VALUE_CHANGE| 1024| | 12993| 12992| 267
          3/7/2021 12:35:28 PM 176881675 | HSEvent VALUE_SET| 2048| 003D3811-052-Q65| 927.903| 927.903| 399
          3/7/2021 12:35:28 PM 176882143 | ProcessMessage New automation/arduino_01/binary_sensor/I3
          3/7/2021 12:35:28 PM 176882143 | Update Accepted 44 to off StatusType=0 Payload= off RegExValue=off
          3/7/2021 12:35:28 PM 176882146 | Non-plugin Update Expression REPLACE(REPLACE($$PAYLOAD:,"on",100),"off",0) on payload off
          3/7/2021 12:35:28 PM 176882149 | ActOnMessageForTrigger Topic automation/arduino_01/binary_sensor/I3,Payload=off, Triggers=0
          3/7/2021 12:35:29 PM 176882635 | HSEvent VALUE_CHANGE| 1024| | 12994| 12993| 267
          3/7/2021 12:35:29 PM 176883266 | HSEvent VALUE_CHANGE| 1024| 003D3811-031-Q14| 21| 22| 107
          3/7/2021 12:35:29 PM 176883273 | HSEvent VALUE_CHANGE| 1024| 003D3811-031-Q12| 255| 0| 105
          3/7/2021 12:35:30 PM 176883436 | HSEvent VALUE_CHANGE| 1024| | 12995| 12994| 267
          3/7/2021 12:35:30 PM 176883627 | HSEvent VALUE_SET| 2048| 003D3811-005-Q143| 0| 0| 10
          3/7/2021 12:35:30 PM 176883634 | HSEvent VALUE_SET| 2048| 003D3811-005-Q143| 0| 0| 10
          3/7/2021 12:35:30 PM 176883712 | HSEvent VALUE_CHANGE| 1024| 003D3811-005-Q140| 16.28| 16.5| 7
          3/7/2021 12:35:30 PM 176883718 | HSEvent VALUE_SET| 2048| 003D3811-005-Q140| 16.28| 16.28| 7
          3/7/2021 12:35:31 PM 176884636 | HSEvent VALUE_CHANGE| 1024| | 12996| 12995| 267
          3/7/2021 12:35:32 PM 176885437 | HSEvent VALUE_CHANGE| 1024| | 12997| 12996| 267
          3/7/2021 12:35:33 PM 176886637 | HSEvent VALUE_CHANGE| 1024| | 12998| 12997| 267
          3/7/2021 12:35:34 PM 176887438 | HSEvent VALUE_CHANGE| 1024| | 12999| 12998| 267
          3/7/2021 12:35:34 PM 176887464 | HSEvent VALUE_SET| 2048| 003D3811-030-Q9| 9| 9| 101


            The expression needs to identify the payload as being a string rather than a number by adding quotes around $$PAYLOAD:



              Hi Mike,

              Thanks for that input... I'll try it once I can get past where I'm stuck.

              I just can't get the following to work. Sorry for the long post...

              HS3 on Linux

              I have an existing HS Device that is controlled with a Value of 0/1 or a status of off/on (Device Ref=481)
              NOTE: The existing device It is assigned a HC/DC of M6 a Device Type (String) of "Motion Detector" -- not sure if this matters
              The topic being sent to the Mosquitto broker is homeassistant/binary_sensor/M6/state with a payload of on/off
              mscMQTT shows the payload changing (in the payload column) every time a payload is sent.


              1) I go to mscMQTT-->Associations
              2) In the MQTT Table I find the topic that I want to control that device with (homeassistant/binary_sensor/M6/state)
              3) I click in the ref column text box and enter 481 (the device reference), and click submit (see below)
              NOTE: The devices listed in Blue below are not working either.
              Click image for larger version

Name:	Step_03.png
Views:	188
Size:	65.1 KB
ID:	1461474
              4) At this point, the device does not change with published topics.
              5) When I refresh the association table (click show Selected associations) the 481 disappears for that topic (see below)
              NOTE: after completing steps 5-7 and doing the same thing for a second device, both the new device and device 481 show up in the association table (see Step 8)
              Click image for larger version

Name:	Step_04.png
Views:	126
Size:	65.3 KB
ID:	1461475

              5) Clicking "Next" through all my listed associations, I don't see any reference to the Device (a "pink" Dev: in the Topic column).

              -- Side question... How to Devices get added to the Association table (listed in Red / Pink)?? I've toggled device 481 several times with the Device control buttons it still doesn't show up in that list.

              6) If I go to add/edit and enter 481 this is what I get:
              Click image for larger version

Name:	Step_06.png
Views:	120
Size:	36.5 KB
ID:	1461476
              7) If I enter "homeassistant/binary_sensor/M6/state" in the "MQTT Subscribe (control) Topic, it then looks like this:
              NOTE: The assocation for the topic looks that same as in Step 4
              Click image for larger version

Name:	Step_07.png
Views:	126
Size:	48.2 KB
ID:	1461477

              8) Only after adding a second device using steps 1-7, both device 481 and the new device (476) showed up in the association table. The first device still works, the second device does not.

              Full disclosure: Before doing any of this, I stopped the mscMQTT plug-in, deleted all files associated with mscMQTT (HSPI, bin, Data, Config, etc.). I then re-installed from the updater. I didn't re-install the .DLL you pointed me to.


                If you have an existing HS device (i.e. non-plugin device) then you will start on the Association tab showing non plugin device (pink). You will click the A column checkbox to associate a MQTT topic with that device. A default publish topic will be created. You will likely want to edit it. Note the General tab has the template for a default pub topic. This topic will be used to send status of the HS device.

                If you then want to also control the device via MQTT then will also add a sub (control) topic. On the next refresh of the page the row will now be in blue to indicate non-plugin bi-directional device.

                There is an issue with bidirectional control using the plugin version in the updater. Duplicate entries are created in the database and this causes the MQTT control aspects not functional. has improved it, but there is another active thread about using MQTT for syncing two HS installs and it looks as if there is still something that is not quite correct. I am actively working that.


                  Ok, that helps... But after the re-install of mscMQTT, I only saw a couple devices in pink -- nearly all items listed on the associations page were discovered topics . I have hundreds of devices in Homeseer. I think I've tried every combination of clearing filters, rebuilding filters, on the association page to get the devices to show up. I also tried manually turning the devices on /off to see if that would make them populate in the mscMQTT association list, but it didn't.

                  The association screen seems to only find 48 topics/devices. The 2 or 3 devices that did show up pink, I've already tried to connect with mostly unsuccessful results.

                  I must be missing something pretty basic. I do appreciate your continued help with this.

                  Click image for larger version

Name:	Association Screen.png
Views:	117
Size:	585.8 KB
ID:	1461596


                    The general page has a setting to enumerate all HS devices on startup. It also has a button at the bottom to manually enumerate them. The enumeration can be a slow process and the device list that may be of interest for MQTT association does not change very often so the manual enumeration is what I normally do.

                    I do recognize the process that you used to associate an existing HS non-plugin device to a MQTT topic is a reasonable one and I should be able to handle it in the plugin. I will look into it.


                      The process you used starting with a sub topic and entering a non-plugin ref number will work with HS4 HS3 It also does not require the enumeration of HS devices to use the ref of a non-plugin device.


                        Thanks for adding that feature and all of your help with this. Unfortunately, I'm still struggling...

                        Here's what I've done:
                        1) Stopped the mcsMQTT plug-in
                        2) Uninstalled via the Plug-in Manager
                        3) Removed every mcsMQTT file in the HomeSeer folder strucure
                        4) Installed using the updater_override process
                        All the above worked as planned.

                        Here's what I did to add control to an existing device. mcsMQTT receives the payload, but the device never changes:

                        I want to be able to have Device 476 controlled by homeassistant/binary_sensor/M1/state
                        I click in the red box below, enter 476, and submit

                        Click image for larger version

Name:	Step_01.png
Views:	164
Size:	137.1 KB
ID:	1462257
                        The topic changed to the device and the MQTT topic that I believe mcsMQTT creates
                        The control does not work at this point

                        Click image for larger version

Name:	Step_03.png
Views:	102
Size:	60.3 KB
ID:	1462259

                        I then click on the 476 button

                        Click image for larger version

Name:	Step_02.png
Views:	125
Size:	57.1 KB
ID:	1462258

                        I would have expected the "MQTT Subscribe (control) Topic" to be populated with "homeassistant/binary_sensor/M1/state"
                        I put homeassistant/binary_sensor/M1/state in the "MQTT Subscribe (control) Topic" field and click "submit"
                        The MQTT payload still does not change the device status.

                        Here are some excerpts from 'mcsMQTT Debug.txt' after following this process:

                        3/11/2021 10:10:28 AM 1303792 | ProcessMessage New homeassistant/binary_sensor/M1/state
                        3/11/2021 10:10:28 AM 1303792 | ActOnMessageForTrigger Topic homeassistant/binary_sensor/M1/state,Payload=on, Triggers=0
                        3/11/2021 10:10:28 AM 1303792 | ProcessMessage New homeassistant/binary_sensor/M1/state
                        3/11/2021 10:10:28 AM 1303792 | ActOnMessageForTrigger Topic homeassistant/binary_sensor/M1/state,Payload=on, Triggers=0
                        3/11/2021 10:10:29 AM 1304214 | HSEvent VALUE_CHANGE| 1024| | 43874| 43873| 267
                        3/11/2021 10:15:57 AM 1632616 | ProcessMessage New homeassistant/binary_sensor/M1/state
                        3/11/2021 10:15:57 AM 1632616 | ActOnMessageForTrigger Topic homeassistant/binary_sensor/M1/state,Payload=on, Triggers=0
                        3/11/2021 10:15:57 AM 1632616 | ProcessMessage New homeassistant/binary_sensor/M1/state
                        3/11/2021 10:15:57 AM 1632616 | ActOnMessageForTrigger Topic homeassistant/binary_sensor/M1/state,Payload=on, Triggers=0
                        3/11/2021 10:15:58 AM 1633226 | HSEvent VALUE_CHANGE| 1024| | 44203| 44202| 267
                        3/11/2021 10:15:59 AM 1634426 | HSEvent VALUE_CHANGE| 1024| | 44204| 44203| 267
                        3/11/2021 10:16:00 AM 1635227 | HSEvent VALUE_CHANGE| 1024| | 44205| 44204| 267
                        3/11/2021 10:16:01 AM 1636435 | HSEvent VALUE_CHANGE| 1024| | 44206| 44205| 267
                        3/11/2021 10:16:02 AM 1637235 | HSEvent VALUE_CHANGE| 1024| | 44207| 44206| 267
                        Is there anything in my device configuration that could be the problem??

                        Click image for larger version

Name:	Dev_01.png
Views:	116
Size:	51.8 KB
ID:	1462260

                        Click image for larger version

Name:	Dev_02.png
Views:	100
Size:	36.0 KB
ID:	1462261

                        Click image for larger version

Name:	Dev_03.png
Views:	101
Size:	50.7 KB
ID:	1462262


                          Side question... I've started re-creating the devices by checking the "a" column next to the topic that I want to control the device with. Why does checking that box create 2 devices?

                          If I delete the 128 device, then both go away. When I check the "a" box again, only one device is created.

                          Click image for larger version

Name:	Dev_98.png
Views:	104
Size:	15.1 KB
ID:	1462277

                          Click image for larger version

Name:	Dev_99.png
Views:	101
Size:	18.6 KB
ID:	1462275
                          Attached Files


                            The post #12 issue was caused by a lack of update of internal dictionary when the database was changed to reflect the association. I will post a fix after I look into #13. A plugin restart should also fix the problem since the database was correctly updated.

                            HS4 does not allow controls on devices and does not allow devices without parents. To facilitate the migration I have tried to make mcsMQTT behave the same for HS3 and HS4. It is a little difficult to manage. I need to understand why the second use of "a" did not create the parent.


                              I have the update at for HS3 and for HS4. Should be 20 minutes of so upload.