JSON + jq mathematics on multiple idx values

All kinds of 'OS' scripts

Moderator: leecollings

Post Reply
Oystein
Posts: 3
Joined: Tuesday 22 March 2022 14:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

JSON + jq mathematics on multiple idx values

Post by Oystein »

I can read multiple values divided over as many idx data.

In bash I can do some mathematical as shwon in the 3rd line but somehow it pastes the 2nd value behind the first without really adding them together like 1 + 2 = 3

bash script Epower.sh:
#!/bin/bash

curl -s "http://localhost:8060/json.htm?type=devices&rid=1" | jq -r '.result[0] .Counter'
curl -s "http://localhost:8060/json.htm?type=devices&rid=1" | jq -r '.result[0] .CounterDeliv'
curl -s "http://localhost:8060/json.htm?type=devices&rid=1" | jq -r '.result[0] .Counter + .result[0] .CounterDeliv'
curl -s "http://localhost:8060/json.htm?type=devices&rid=17" | jq -r '.result[0] .Data'

Outcome:

root@raspberrypi:/home/pi# /home/pi/scripts/Epower.sh
6961.507
4468.416
6961.5074468.416
2328 Watt

And additionally I have a 4th value from idx 17 to which I also want to do an add and minus caluculation but how do I mix that in the equation ?
I understand I need to make the value "clean" without the "Watt" designation but then I still do not know how to make a calculation with values from both idx 1 (Power meter) and idx 17 (Solar Inverter) in the samle mathematical calculation.

Who can help me with the above issues ?
Thank you.
Oystein
Posts: 3
Joined: Tuesday 22 March 2022 14:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: JSON + jq mathematics on multiple idx values

Post by Oystein »

In the meantime I continued with the setup of a database (InfluxDB) and a custom dashboard (Dashticz).

In Dashticz I can do the required calculations and show the output as a value / graph according to the manual.

Problem solved :D
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests