This is the forum archive of Homey. For more information about Homey, visit the Official Homey website.
The Homey Community has been moved to https://community.athom.com.
This forum is now read-only for archive purposes.
The Homey Community has been moved to https://community.athom.com.
This forum is now read-only for archive purposes.
Closed
need some help with json flow
Hi,
I'm trying to get things automated with flows but I'm not able to get it right.
Input is to fetch every x time a url which contains a token and response with json list output.
This list can be empty (so contain only []) or contain data (1 or multiple id's) :
Input is to fetch every x time a url which contains a token and response with json list output.
This list can be empty (so contain only []) or contain data (1 or multiple id's) :
[
{
id: 93930,
created_at: "2016-04-11T13:30:19.379+02:00",
message: {
body: "BVD graag contact RAC",
received_at: "2016-04-11T13:30:19.375+02:00",
address: {
street_name: null,
house_number: null,
postcode: null,
city: null,
latitude: null,
longitude: null
}
},
incident_responses: [some other data]
}
]
If the list contains data, I would like to use the latest (in case of multiple id's) value of the body variable (in this case "BVD graag contact RAC" to be output via speech by homey and trigger some other actions (switch lights, etc)
Can somebody put me in the right direction ?
If the list contains data, I would like to use the latest (in case of multiple id's) value of the body variable (in this case "BVD graag contact RAC" to be output via speech by homey and trigger some other actions (switch lights, etc)
Can somebody put me in the right direction ?
This discussion has been closed.
Comments
alternative is to buy a Rapberry PI. Put Node-RED and Mosquitto on it. That you use to get the json and determine the body variable. Publish the result using MQTT. This can all be done in the context of Node-RED. Drag and drop.
Install Mosquitto MQTT client on the Homey and subscribe to the topic you just published in. Do what you want with the result here.
Thanks for your response.
I've installed the "HTTP request flow cards" app which can do something with json and I'm struggling to get that right.
Maybe I'm wrong and it's not possible with that app, or maybe I need better logic as well.
1:
A time triggered flow with action 'GET variable step 1'.
In the JSON path variable use something like this: $[0].message.body
In the trigger variable type something like 'ImOnFire'.
(you can test and improve this JSON path expression on http://jsonpath.com/).
2:
In the second flow start with the 'GET variable step 2' trigger card, with parameter 'ImOnFire'.
The value 'BVD graag contact RAC' is now in a token and you can use it in conditions and actions.
Good luck!
Thanks, I'll try this!
Still waiting for the first alarmering to check if it works
Can I ask a feature request ?
I would like to be able to set multiple variable with one get request (if you want to add an extra variable click the + sign for a new variable).
For example to get $[0].message.body with variable 'alarmeringsbericht' and $[0].message.received_at with variable 'alarmeringstijd'
It is not possible to make something dynamic, because flow cards does not allow a variable number of tokens or parameters. But i can create a new card that allow two json path expressions and an extra 'step 2' trigger card with those two tokens.
I mean this, by clicking the + sign you're able to add an extra json variable.
Don't know if this is possible but it to me it would be great.
IMHO I don't need changes to step 2 because I can get either variable1 or variable 2.