Announcement

Collapse
No announcement yet.

JSON Action

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

    JSON Action

    I am using MQTT to send a JSON output from APLR on a Linux box to Homeseer using MQTT (mosquitto pub). It works well.

    I am also sending JSON to Homeseer over HTTP using Curl to execute Homeseer JSON commands. For example,
    http://192.168.0.X/JSON?request=hsversion

    *https://docs.homeseer.com/display/HSPI/JSON+API*

    Is it possible to send JSON commands to mcsMQTT that would execute locally on HS? ex. hsversion, voicecommand, etc...
    mcsMQTT could reply with the Homeseer reply?
    HS3 Pro Edition 3.0.0.435 (Windows Server 8.1 on ESXi box)

    Plug-Ins Enabled:
    Z-Wave:,RaspberryIO:,AirplaySpeak:,Ecobee:,
    weatherXML:,JowiHue:,APCUPSD:,PHLocation:,Chromecast:,EasyTr igger:

    #2
    What is your list of commands that you would like to have interpreted and executed? What is the convention for parameter passing? What about convention for returned results for the query cases?

    Comment


      #3
      Originally posted by Michael McSharry View Post
      What is your list of commands that you would like to have interpreted and executed? What is the convention for parameter passing? What about convention for returned results for the query cases?
      I would think that there would be a button to subscribe to a topic and mcsMQTT would just take that JSON request and pass it to HS. If HS interpreted it, great. MQTT would just put the response on the same or another topic.

      It would be up to the sending agent to make sure it is a valid JSON request. If not, just pass the error along on the topic.
      HS3 Pro Edition 3.0.0.435 (Windows Server 8.1 on ESXi box)

      Plug-Ins Enabled:
      Z-Wave:,RaspberryIO:,AirplaySpeak:,Ecobee:,
      weatherXML:,JowiHue:,APCUPSD:,PHLocation:,Chromecast:,EasyTr igger:

      Comment


        #4
        I think you are asking for the same behavior that is achieved with REST POST protocol, but using a pair of MQTT topics as the transport mechanism. Am I correct?

        Comment


          #5
          Originally posted by Michael McSharry View Post
          I think you are asking for the same behavior that is achieved with REST POST protocol, but using a pair of MQTT topics as the transport mechanism. Am I correct?
          Essentially, yes. Incoming JSON requests over MQTT would simply be converted to REST calls on the localhost with mcsMQTT, and the return Value passed back over MQTT. The format of the request doesn't really need to be checked. Just acting as a tunnel.

          https://docs.homeseer.com/display/HSPI/speak

          So for example, if a subscribed TOPIC (Let's say it is called "HS_ACTIONS") has a JSON payload.

          {"action":"speak","phrase":"Speaker test"}.

          (not sure if that action is the proper keyword or request. I think there is a standard here)

          That would resolve to http://localhost/JSON?request=speak&...Speaker%20Test

          This would respond with something like:

          { "Response":"ok" }

          This would then be the MQTT message on TOPIC HS_RESPONSE (or whatever it was set to).

          This request would return an error. mcsMQTT doesn't care... It is just a conduit.

          {"action":"fatfinger","phrase":"woops"}
          { "Response":"Error, bad request" }

          //////////////////////////////////////////////
          Right now, I am using MQTT to move JSON into HS variables and it works awesome.

          I have a camera overloooking the driveway. Blue Iris takes several photos when a car drives over the driveway sensor. I have a script which runs ALPR on those pictures and sends up the results via mosquitto to HS. I am hoping to use that data in HS to determine which car and which direction (it include coordinates) the car is going.

          Your plug in makes it simple to import these fields.

          ----------------------------------------------
          qwerty@ubuntu18:/backup/ALPR_snapshots$ mosquitto_pub -h localhost -t "License Plate" -m `alpr -j Untitled.jpg`
          qwerty@ubuntu18:/backup/ALPR_snapshots$ alpr Untitled.jpg
          plate0: 10 results
          - 747ZB5 confidence: 90.0509
          - 7A7ZB5 confidence: 87.5208
          - 747Z85 confidence: 82.9257
          - 77ZB5 confidence: 81.1959
          - 7472B5 confidence: 80.665
          - 747ZBS confidence: 80.5054
          - 7A7Z85 confidence: 80.3956
          - 747Z5 confidence: 79.7856
          - 747ZG5 confidence: 78.6453
          - 747ZS5 confidence: 78.2875
          ----------------------------------------------

          Click image for larger version

Name:	Screen Shot 2020-08-04 at 10.37.16 AM.png
Views:	469
Size:	349.8 KB
ID:	1408404

          ///////////////////////////////////////////////////
          I have another script on this linux box which parses commands from iOS shortcuts over SSH. I am using curl to do this. Works fine.

          #Called from iOS shortcuts. SPEAK will be the text
          PHRASE=`urlencode $SPEAK`
          RETURN=`curl http://192.168.0.5/JSON?request=voicecommand\&phrase=$PHRASE`
          echo $RETURN

          ////////////////////////////////////////////////

          Sorry if this is long winded, but that sort of explains my use case. In one case, I am sending JSON data. In the other, I am sending JSON actions. Using two different methods. Both work fine for me, I am just wondering if it makes sense to have one way to do both?

          It sort of assumes the MQTT network is secure: and it gives the MQTT nodes lots of power, but it specifically would need to be enabled.

          My use case could be WAY off base. I am sort of new to MQTT and have zero knowledge of node-red-- so take this with a huge grain of salt.
          HS3 Pro Edition 3.0.0.435 (Windows Server 8.1 on ESXi box)

          Plug-Ins Enabled:
          Z-Wave:,RaspberryIO:,AirplaySpeak:,Ecobee:,
          weatherXML:,JowiHue:,APCUPSD:,PHLocation:,Chromecast:,EasyTr igger:

          Comment

          Working...
          X