Hi !
Thanks for all that good advices !
Actually, I had already did some tests with a current state node to know wich entity’s propertity give me the latitude and longitude.
With an inject and a debug node, getting those data with $entity().attributes.latitude and $entity().attributes.longitude when device_tracker.oneplusseb is set as Entity ID is OK.
My problem is that I don’t know where I have to put my condition test for the action to be performed.
When I’m testing with current state node and debug, everything is ok because I can put the following JSONata in output msg.payload and then get msg.payload in my debug node wich print Away or InZone
.
(
$entity().attributes.latitude > 43.30700
) and (
$entity().attributes.latitude < 43.30800
) and (
$entity().attributes.longitude > 5.4123900
) and (
$entity().attributes.longitude < 5.4123930
)? "InZone" : "Away"
But with an Event:state node and a Call service node, where do I put my condition ?
Do I have to put JSONata in the “If State” of the Event:state node ?
In the output msg.payload of the Event:state node ?
And how do I process the result of the test in the Data field of my Call service node to say that I have to be notify only if the information is “InZone” ?
Here is my test flow wich is ok :
[{"id":"539353e7da970795","type":"inject","z":"e4925652bd2af625","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1110,"y":540,"wires":[["c4a29767325f64d2"]]},{"id":"c4a29767325f64d2","type":"api-current-state","z":"e4925652bd2af625","name":"","server":"abcdef12.ghij34","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"device_tracker.oneplusseb","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"test","propertyType":"msg","value":"(\t $entity().attributes.latitude > 45.04400\t) and (\t $entity().attributes.latitude < 45.04500\t) and (\t $entity().attributes.longitude > < 2.48000\t) and (\t $entity().attributes.longitude < < 2.48100\t)? \"InZone\" : \"Away\"","valueType":"jsonata"},{"property":"latitude","propertyType":"msg","value":"$entity().attributes.latitude","valueType":"jsonata"},{"property":"longitude","propertyType":"msg","value":"$entity().attributes.longitude","valueType":"jsonata"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1380,"y":540,"wires":[["9cd6dba19522aa96","05474f6fd2ad28c6","3e5369e9010dc7f2"]]},{"id":"9cd6dba19522aa96","type":"debug","z":"e4925652bd2af625","name":"Test","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"test","targetType":"msg","statusVal":"","statusType":"auto","x":1670,"y":560,"wires":[]},{"id":"05474f6fd2ad28c6","type":"debug","z":"e4925652bd2af625","name":"Latitude","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"latitude","targetType":"msg","statusVal":"","statusType":"auto","x":1680,"y":480,"wires":[]},{"id":"3e5369e9010dc7f2","type":"debug","z":"e4925652bd2af625","name":"Longitude","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"longitude","targetType":"msg","statusVal":"","statusType":"auto","x":1680,"y":660,"wires":[]}]
And here is the flow I’m working on :
[{"id":"467f9da11e3b1abd","type":"server-state-changed","z":"e4925652bd2af625","name":"","server":"abcdef12.ghij34","version":5,"outputs":1,"exposeAsEntityConfig":"","entityId":"device_tracker.oneplusseb","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"(\t $entity().attributes.latitude > 45.04300\t) and (\t $entity().attributes.latitude < 45.04400\t) and (\t $entity().attributes.longitude > 2.48000\t) and (\t $entity().attributes.longitude < 2.48100\t)? \"InZone\" : \"Away\"","valueType":"jsonata"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":1160,"y":320,"wires":[["c67315962ddbfce7"]]},{"id":"c67315962ddbfce7","type":"api-call-service","z":"e4925652bd2af625","name":"","server":"abcdef12.ghij34","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_oeplusw4","areaId":[],"deviceId":[],"entityId":[],"data":"{\t\"message\":payload,\t \"title\":\"Specific zone\"\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1580,"y":320,"wires":[[]]}]