Announcement

Collapse
No announcement yet.

Attempting to parse JSON to device name and value

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

    Attempting to parse JSON to device name and value

    Hi,
    I get the impression BIG5 should be able to do this, but I could be wrong..


    I'm trying to use JSON string sent over a serial link, to create or update a device with a value.

    A typical string is
    Code:
    {"sig":"S1","val":"    68.7"} cr lf
    These parsing lines work correctly in the test box, but used in the serial port input setup, I get JSON in the device name and no value?
    HVAC_Sensor_${ JSON(input, "sig") }
    ${ JSON_Num(input, "val") }

    I am using using the "unbraced" version in the serial input device name & value, eg.

    HVAC_Sensor_${ JSON(input, "sig")}
    JSON_Num(input, "val")

    The result is just a single device like "Big5 SERIAL HVAC_Siemens - ${HVAC_Sensor_${JSON(input, "sig")}}"


    What I was expecting was a set of eight devices named HVAC_Sensor_S1 to HVAC_Sensor_S8, with the temperature values being updated in them?

    I'm pretty sure I am doing something really daft, but I cannot figure out what!


    The data is being sent from my program in a Siemens PLC, a screen grab of "live" input serial as monitored on the homeseer machine using realterm is below, to show the existing data set.

    It sends one line each second, so eight seconds to update all eight values; it's temperature data that only changes slowly so no need for high speed updates. I only have four sensors wired so far to test the system.

    Any assistance appreciated!

    Rob.


    Click image for larger version  Name:	Serial_Data_Grab.png Views:	0 Size:	52.4 KB ID:	1448541

    #2
    rjenkinsgb

    Welcome to Big5 ! You are doing very well, just forgot to remove the ${...} wrap in your name expression and to use + sign to concatenate two strings.

    1. Try this in the Serial Profile

    Name expression

    Code:
    JSON(input, "sig")
    Value expression

    Code:
    JSON_Num(input, "val")
    I tested both in my Big5 sand box and they both work with your sample JSON file.

    2. If you want a "fancy" name for each sensor you can modify the name expression like that for example

    Code:
    "Siemens_HVAC_" + JSON(input, "sig")
    3. You can change the "name" of each sensor as well as the "floor" and "room" attributes later after BIG5 creates the devices in HomeSeer. Big5 is smart to remember which one is which and will keep updating them at their new locations and names.

    Hope this helps. Let us know how it went.

    Comment


      #3
      Hi,
      thank you!

      That has got the device name part working; I now have eight named devices. It was the change from ${...} for substitution within a string, to the quoted string and + concatenation - I could not find that info in the documentation (and still cannot from another quick look, I must be looking in the wrong section).


      The devices are now updating regularly according to the timestamps, but are not showing any values.
      I've verified the value expression is as you show it, but though it works in the sandbox there is no result in Homeseer?

      Could it be something to do with the leading spaces in the number? The Siemens number to ASCII or string instructions pad the output to a fixed size with leading spaces.
      OK, just tried with a modded program that reformats the numbers to leading zero or sign, but still no values appearing??

      I've also grabbed the actual data using realterm, to make sure I'd not accidentally used a lookalike character that was not being parsed, but it seems OK..

      eg.
      Code:
      {"sig":"S0","val":"000062.6"}
      {"sig":"S1","val":"000061.5"}
      {"sig":"S2","val":"000059.0"}
      {"sig":"S3","val":"000043.3"}
      {"sig":"S4","val":"-00000.2"}
      {"sig":"S5","val":"-00000.1"}
      {"sig":"S6","val":"-00000.2"}
      {"sig":"S7","val":"-00000.1"}
      Any thoughts?

      Thanks, Rob.

      Comment


        #4
        This is very strange. Usually the rule that is always valid with Big5 is "If it works in the sandbox than it works in deployment"

        I tested both leading spaces and leading zeros in my sandbox and they both do work nicely with the expression

        Code:
        JSON_Num(Input,"val")

        Furthermore I managed to import values in my test HS4 from your JSON. Here is one HS4 device created from your JSON

        ID
        307
        Device Version
        4
        Value
        62.6
        Status
        Interface
        Big5HS4
        Device Type
        Api: NotSpecified
        Relationship
        Device (Root)
        Associated Devices

        Please enable "Errors and debugging" at the bottom of Big5 configuration page. Find Big5 HomeSeer log entries pertaining to your serial communication and post a copy here.

        Don't worry, we'll figure it out.

        Comment


          #5
          Correction - if I go to device > status, it does have the correct value, it's just not showing it in the device list?
          Operator error again, at a guess...

          The device version is not the same as your example, though. Is that relevant?

          ID
          617
          Device Version
          3.2
          Value
          52.3
          Status
          Interface
          Big5
          Device Type
          Api: NotSpecified
          Relationship
          Not_Set
          Associated Devices



          Hi,
          it seems to be seeing the data and values in the log OK; no errors:

          Code:
          1/16/2021 23:13:39
          Legacy-Plugin
          Big5
          [Big5 Plugin] [SERIAL HVAC_Siemens (COM7, 9600bps) IN]: -0.2
          1/16/2021 23:13:39
          Legacy-Plugin
          Big5
          [Big5 Plugin] [Raw message in]: {"sig":"S4","val":"-00000.2"}
          1/16/2021 23:13:39
          Legacy-Plugin
          Big5
          [SerialService] [Serial RAW IN]: {"sig":"S4","val":"-00000.2"}
          1/16/2021 23:13:38
          Legacy-Plugin
          Big5
          [Big5 Plugin] [SERIAL HVAC_Siemens (COM7, 9600bps) IN]: 45.9
          1/16/2021 23:13:38
          Legacy-Plugin
          Big5
          [Big5 Plugin] [Raw message in]: {"sig":"S3","val":"000045.9"}
          1/16/2021 23:13:38
          Legacy-Plugin
          Big5
          [SerialService] [Serial RAW IN]: {"sig":"S3","val":"000045.9"}
          1/16/2021 23:13:37
          Legacy-Plugin
          Big5
          [Big5 Plugin] [SERIAL HVAC_Siemens (COM7, 9600bps) IN]: 56.1
          1/16/2021 23:13:37
          Legacy-Plugin
          Big5
          [Big5 Plugin] [Raw message in]: {"sig":"S2","val":"000056.1"}
          1/16/2021 23:13:37
          Legacy-Plugin
          Big5
          [SerialService] [Serial RAW IN]: {"sig":"S2","val":"000056.1"}
          1/16/2021 23:13:36
          Legacy-Plugin
          Big5
          [Big5 Plugin] [SERIAL HVAC_Siemens (COM7, 9600bps) IN]: 58.9
          1/16/2021 23:13:36
          Legacy-Plugin
          Big5
          [Big5 Plugin] [Raw message in]: {"sig":"S1","val":"000058.9"}
          1/16/2021 23:13:36
          Legacy-Plugin
          Big5
          [SerialService] [Serial RAW IN]: {"sig":"S1","val":"000058.9"}
          1/16/2021 23:13:35
          Legacy-Plugin
          But no device values appear:

          Click image for larger version  Name:	homeseer_devices.png Views:	0 Size:	291.8 KB ID:	1448665

          Comment


            #6
            OK, got it; I needed to configure each device with a range and enable status etc.

            Many thanks for the help!

            Comment

            Working...
            X