Help Getting Values From JSON in webCoRE

I have a cron job that polls a REST API for some JSON and saves it to my server so that it can be accessed via webCoRE. That part is working just fine. I can use use a GET request in webCoRE to pull in that JSON. The problem I’m having is I don’t know how to get the variables from the JSON so that I can use them. My goal is to pull a couple of temperature values and apply those values to a couple of virtual sensors. Any help would be appreciated. Even if you just point me to a tutorial that would be fine.

Also, if anyone knows a way to do a GET request in webCoRE using an auth token that would be a huge help. As best as I can tell it only supports username and password authentication which is why I’m currently doing it the way that I’m doing it with the cron and server.

You may want to post your question on the webcore forum at https://community.webcore.co

What does the json response look like?

[
    {
        "id": XXXXXX,
        "title": "XXXXXX",
        "created": "2019-04-04T23:04:25.732947Z",
        "uuid": "XXXXXXXXXXXXXXXXXXXXXXXX",
        "hardware_id": "XXXXXXXXX",
        "latest_temps": [
            {
                "channel": 1,
                "created": "2019-04-05T16:04:11Z",
                "degreetype": 2,
                "temp": 62.8
            },
            {
                "channel": 2,
                "created": "2019-04-05T16:04:11Z",
                "degreetype": 2,
                "temp": 63.7
            }
        ],
        "device_log": {
            "memUsage": "2.6M/4.2M",
            "timeZoneBT": "America/New_York",
            "tempFilter": "true",
            "diskUsage": "0.2M/16.0M",
            "deviceID": "86a4e234-6743-4aba-8ebf-0922eb3d2cb9",
            "mode": "Managed",
            "versionImage": "201703260554",
            "frequency": "2.4 GHz",
            "commercialMode": "false",
            "version": "0.2.7",
            "vBatt": 4.148,
            "versionNode": "5.0.0",
            "cpuUsage": "74%",
            "vBattPerRaw": 0.979,
            "vBattPer": 0.9988374112195121,
            "macNIC": "30:ae:a4:df:8d:34",
            "bleClientMAC": "",
            "linkquality": "100/100",
            "onboardTemp": 74.12515923566879,
            "date": "2019-04-05 16:00:23 UTC",
            "drivesettings": "{\"p\":4,\"s\":1,\"d\":7,\"ms\":100,\"f\":0,\"l\":1}",
            "txpower": 78,
            "uptime": "6:50",
            "signallevel": -41,
            "contrast": "7",
            "ssid": "Samsung Connect",
            "band": "802.11bgn",
            "macAP": "XXXXXXXX",
            "boardID": "GG7KRDK67",
            "model": "FBX11D",
            "versionUtils": "6.1.3",
            "auxPort": "",
            "versionJava": "7.6.5",
            "publicIP": "XXXXXXXXXXXX",
            "versionEspHal": "HAL: V1R2;AVR: 0.0.14;",
            "internalIP": "192.168.X.X",
            "bleSignalLevel": -101
        },
        "last_templog": "2019-04-05T16:04:11Z",
        "last_battery_reading": null,
        "channels": [
            {
                "id": 2199791,
                "channel_label": "Channel 1",
                "channel": 1,
                "current_temp": 62.8,
                "created": "2019-04-04T23:06:09Z",
                "enabled": true,
                "notify_email": true,
                "notify_sms": true,
                "temp_max": null,
                "temp_min": null,
                "minutes_buffer": null,
                "range_average_temp": 66.7,
                "range_max_temp": 69.8,
                "range_min_temp": 62.8,
                "alerts": [],
                "sessionid": 374664,
                "last_templog": {
                    "temp": 62.8,
                    "degreetype": 2,
                    "created": "2019-04-05T16:04:11Z"
                }
            },
            {
                "id": 2199792,
                "channel_label": "Channel 2",
                "channel": 2,
                "current_temp": 63.7,
                "created": "2019-04-04T23:06:09Z",
                "enabled": true,
                "notify_email": true,
                "notify_sms": true,
                "temp_max": null,
                "temp_min": null,
                "minutes_buffer": null,
                "range_average_temp": 67.3,
                "range_max_temp": 75.8,
                "range_min_temp": 63.2,
                "alerts": [],
                "sessionid": 374664,
                "last_templog": {
                    "temp": 63.7,
                    "degreetype": 2,
                    "created": "2019-04-05T16:04:11Z"
                }
            },
            {
                "id": 2199793,
                "channel_label": "Channel 3",
                "channel": 3,
                "current_temp": null,
                "created": "2019-04-04T23:06:09Z",
                "enabled": true,
                "notify_email": true,
                "notify_sms": true,
                "temp_max": null,
                "temp_min": null,
                "minutes_buffer": null,
                "range_average_temp": null,
                "range_max_temp": null,
                "range_min_temp": null,
                "alerts": [],
                "sessionid": 374664,
                "last_templog": null
            },
            {
                "id": 2199794,
                "channel_label": "Channel 4",
                "channel": 4,
                "current_temp": null,
                "created": "2019-04-04T23:06:09Z",
                "enabled": true,
                "notify_email": true,
                "notify_sms": true,
                "temp_max": null,
                "temp_min": null,
                "minutes_buffer": null,
                "range_average_temp": null,
                "range_max_temp": null,
                "range_min_temp": null,
                "alerts": [],
                "sessionid": 374664,
                "last_templog": null
            },
            {
                "id": 2199795,
                "channel_label": "Channel 5",
                "channel": 5,
                "current_temp": null,
                "created": "2019-04-04T23:06:09Z",
                "enabled": true,
                "notify_email": true,
                "notify_sms": true,
                "temp_max": null,
                "temp_min": null,
                "minutes_buffer": null,
                "range_average_temp": null,
                "range_max_temp": null,
                "range_min_temp": null,
                "alerts": [],
                "sessionid": 374664,
                "last_templog": null
            },
            {
                "id": 2199796,
                "channel_label": "Channel 6",
                "channel": 6,
                "current_temp": null,
                "created": "2019-04-04T23:06:09Z",
                "enabled": true,
                "notify_email": true,
                "notify_sms": true,
                "temp_max": null,
                "temp_min": null,
                "minutes_buffer": null,
                "range_average_temp": null,
                "range_max_temp": null,
                "range_min_temp": null,
                "alerts": [],
                "sessionid": 374664,
                "last_templog": null
            }
        ],
        "fbj_version": "7.6.5",
        "fbn_version": "5.0.0",
        "fbu_version": "6.1.3",
        "version": "0.2.7",
        "probe_config": "8|0|0.0|8|0|0.0|8|0|0.0|8|0|0.0|8|0|0.0|8|0|0.0",
        "last_drivelog": null
    }
]

What do you get when you log the $response variable after the webcall?

Not sure which temp you’re trying to pull out but here’s an example…

image

image

I’m still learning webCoRE and JSON but I think this is what you’re asking for:

temps

My reply above has an example of pulling one of the temps from the json response. Which temperature are you trying to get?

The two temperatures in your example are exactly the two I am looking for. I tried copying your formatting but I’m not getting the same result. How do you get the /* #3 */ there and what is that doing?

Once I have those values how would I apply them to virtual sensors?

The text in gray is just used when you enable the Trace button below the piston, it helps in debugging, that is all.

Here’s an importable piston example so you can inspect how I put it together. Just note that it doesn’t have a trigger, I have to execute it manually.

You can save the temperature you extracted to a variable, like…
set temp1 = $response.[0].latest_temps.[0].temp

Then from there use whatever command the virtual sensor uses to apply that variable to it. It can be done in shorter steps, just wanted to show you the process. Do you have a link to the virtual sensor?

How would I link to the virtual sensor? It’s the one titled “simulated temperature sensor” in the IDE. I’ve used it before to clone values to so I assume it should work for this as well.

I meant the thread here in the ST forum where I can check it out, then I can tell you how to set the temp

I might be misunderstanding you but there’s no thread. This is the first question I’ve asked in reference to this project.

When you created the virtual temp sensor, where did you get the code that you used in the IDE?

I opened the IDE, went to “My Devices” then clicked “+ New Device”. I gave it a name and a network ID then selected “simulated temperature sensor” from the “type” drop down field. I clicked “create” and now I have a virtual sensor.

It should look like this… the ‘Log to console’ task can be removed or just left as is when you get it working how you want it.

Oops, I just noticed I overwrote the temp1 with temp2 variable. You’ll need to set another task to set the temp2 to another virtual device if you have another one.

Thanks. I’m still trying to make sense of all of this but I think I’m headed in the right direction.

So should the set variable fields have the same values as the log info fields? Is that what you mean when you said overwrote the temp1 with the temp2 variable?

The set variable should and log info should have the same contents just so you know what values are being generated and set.

If you look at line 32, it’s doing the same thing as line 31 so it’s overwriting the value we just set. What you need is another task that will setTemperature({temp2}) to another virtual temp device so you will end up with two devices with two readings.

Thanks again for helping me out. I’m still trying to understand what I’m doing rather than just using your pistons. When I use your example with my address in the GET request I’m not seeing the same values logged. How do you determine the expression to use with $response?

Get an anonymized (green camera) version of your piston and post it here so we can have a look.

This is your piston with the device changed to my virtual device and URL changed to the URL of the .json. I didn’t make any other changes. Running a test only returns “200”.