I have a little question... the only thing I want to do is to read the state of a switch in Bash...
how can I do that? I can use json but, not found how to call a specific value (Data or Status) of a switch..
I have a script (doorbell) which needs to check if gong is turned on yes or no, based on that the gong works or not...
jadijkstra2000 wrote: ↑Friday 10 July 2020 16:30
I have a script (doorbell) which needs to check if gong is turned on yes or no, based on that the gong works or not...
domoticzIP=127.0.0.1
domoticzPort=8084
gongIDX=382
devicestatus=$(curl -s "$domoticzIP:$domoticzPort/json.htm?type=devices&rid=$gongIDX" | grep '"'Status'"' )
if [[ $devicestatus == *"On"* ]]; then
echo Gong is On
else
echo Gong is Off
fi
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
heggink wrote: ↑Friday 10 July 2020 17:58
probably better to not grep for Status (which returns the entire Status = "result" line)
Please help me understand why you think using jq is better. My example does grep for "Status" so including the quotes.
I timed both methods bout could not see any difference in result nor in real, -user and sys times
As I said, grep returns the entire line "Status" : "Off" and puts that into variable devicestatus. Either you check against that (instead of just "On" or "Off") or you use jq to only return the "Status" variable's value or just put the 3rd argument into devicestatus (there's lot's of ways). Since the output is json, a json processor might be easier to also test other fields and their values. Just a thought.
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)