hey,
The past few months I’ve been drawn more and more into hass, how incredibly addictive this is! I have and ask about using the REST sensor and json in hassio.
Im try to see when the door was last opened and by whom. unfortunately they do not have a nice api and I can not call per door with last open or other options and I am bound by transactions.
my goal is to compare if a door has been open in the past 2 days, if so change state of sensor to ‘’ inside ‘’. and I want to see if I can see when a specific person was last in, so eg sensor.room3.attributes [“date”]
- platform: rest
name: zkteco test
json_attributes:
- message
- data
resource: http://12.12.12.12:1234/api/transaction/device/{deviceSn}?deviceSn=AJQE182660067&pageNo=1&pageSize=50&access_token=121212
value_template: '{{ value_json.code }}'
- platform: template
sensors:
data:
friendly_name: 'zkdata'
value_template: '{{ states.sensor.zktest_test.attributes["data"] }}'
code:
friendly_name: 'zkmessage'
value_template: '{{ states.sensor.zktest_test.attributes["message"] }}'
here’s the json response i get form the api now i get this info as a attribute
{
"code": 0,
"message": "success",
"data": [
{
"id": 947571,
"eventTime": "2020-06-26 13:02:15",
"pin": "123456789",
"name": "iemand naam 5",
"lastName": "",
"deptName": "Team",
"areaName": "0",
"cardNo": "123456789",
"devSn": "A67",
"verifyModeName": "Only Card",
"eventName": "Normal Verify Open",
"eventPointName": "room1",
"readerName": "1-1",
"accZone": null,
"devName": "1",
"logId": 36173
},
{
"id": 947571,
"eventTime": "2020-06-26 13:02:15",
"pin": "123456789",
"name": "iemand naam 2",
"lastName": "",
"deptName": "Team",
"areaName": "0",
"cardNo": "123456789",
"devSn": "A67",
"verifyModeName": "Only Card",
"eventName": "Normal Verify Open",
"eventPointName": "room1",
"readerName": "1-1",
"accZone": null,
"devName": "1",
"logId": 36173
},
{
"id": 947571,
"eventTime": "2020-06-26 13:02:15",
"pin": "123456789",
"name": "iemand naam 2",
"lastName": "",
"deptName": "Team",
"areaName": "0",
"cardNo": "123456789",
"devSn": "A67",
"verifyModeName": "Only Card",
"eventName": "Normal Verify Open",
"eventPointName": "room1",
"readerName": "1-1",
"accZone": null,
"devName": "1",
"logId": 36173
},
{
"id": 947571,
"eventTime": "2020-06-26 13:02:15",
"pin": "123456789",
"name": "iemand naam",
"lastName": "",
"deptName": "Team",
"areaName": "0",
"cardNo": "123456789",
"devSn": "A67",
"verifyModeName": "Only Card",
"eventName": "Normal Verify Open",
"eventPointName": "room3",
"readerName": "1-1",
"accZone": null,
"devName": "1",
"logId": 36173
}
]
}
as i can see my data now i can for example receive the last 50 or 100 transactions on 1 divice. my thinking is to scan these strings and adjust the status of a sensor if that room or person that the sensor is about is mentioned in one of the 50 strings.
I am completely new with this type of work and with json in general, but I love puzzles.
Is there a way to ‘read’ the json as the sensor in question recognizes and adjusts its data if applicable?
thanks a lot in advance!