Announcement

Collapse
No announcement yet.

Transmit HS Device value via MQTT when status updates are generated via script?

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

    Transmit HS Device value via MQTT when status updates are generated via script?

    I'm having a slightly unusual problem, which I hate to ask for your help with yet again, but cannot seem to figure it out..

    I have a virtual device, a counter technically, which obtains it's status updates via a script - the script which essentially calculates the sum total of several energy meters, and dumps it then into one "grid total":

    &hs.setdevicevaluebyref( 796, hs.devicevalueex(238) + hs.devicevalueex(750) + hs.devicevalueex(190) + hs.devicevalueex(171) + hs.devicevalueex(135) + hs.devicevalueex(281) + hs.devicevalueex(308) + hs.devicevalueex(724), True)

    This is run inside an event:
    Click image for larger version  Name:	Screenshot (21).png Views:	0 Size:	177.6 KB ID:	1398189
    The first reference number is the counter, 796, which was created via the MQTT plugin, by manually adding a new association, and checking the box which then creates the HS device.
    Click image for larger version  Name:	Screenshot (22).png Views:	0 Size:	10.0 KB ID:	1398190
    My problem is, the script from the 1st screenshot will properly update the HS device, but will not cause the status to be published to the topic shown in the 2nd screenshot.

    Only when I go to the HS control panel, and manually enter a value here, is the topic then published:
    Click image for larger version  Name:	Screenshot (23).png Views:	0 Size:	27.6 KB ID:	1398191

    My question is, is there a variable or something I can plug in to the mcsMQTT event action that will allow me to manually publish the HS3 device status, as an MQTT message? I tried hs.devicevalueex(796) and that was then simply published as a whole string.
    Click image for larger version  Name:	Screenshot (25).png Views:	0 Size:	46.0 KB ID:	1398192

    #2
    You have four options which come to mind.
    1. When you control a plugin device you must use CAPI if you want HS to call the plugin to update the device. Setting the device value does not tell HS to tell the plugin to act upon the new value.
    2. You can create a virtual device in HS and then associate this non-plugin device in mcsMQTT with the publish topic set as desired and the payload template of $$VALUE:. When you script runs it will raise an event change trigger that will be recognized by mcsMQTT and then it will publish the updated value.
    3. You can augment your script with a second action. That action will be a Send MQTT Message action with the Topic that you want and a payload of $$DVR796): This would be entered as Energy/GridTotal=$$DVR796): in the event action text box.
    4. You can change your event to have only one action to Send MQTT Message in the payload of the message do the sum as you have done in your script but with replacement variable syntax such as $$DVR238):+DVR750): .... etc. No script needed in this case.

    Comment


      #3
      Thank you very much! the #3 option was exactly what I was hoping for!

      Comment

      Working...
      X