Export of IDX to long Topic is solved

All kinds of 'OS' scripts

Moderator: leecollings

Post Reply
PieterS
Posts: 197
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Export of IDX to long

Post by PieterS »

Try to upload a counter of the gassensor from Domoticz to Mindergas.nl.

This is the script:

Code: Select all

#!/bin/bash
#Token to authenicate with mindergas.nl
TOKEN=**************************
#fetch meterstand (use jq to parse JSON object correctly)
METERSTAND=`curl -s "http://127.0.0.1:8084/json.htm?type=devices&rid=734"  | jq '.result[0].Counter'| tr -d '"'`
#Get OS date, and format it corectly.
NOW=$(date +"%Y-%m-%d")
#Build JSON by hand ;-)
JSON='{ "date":"'$NOW'", "reading":"'$METERSTAND'"  }'
#post using curl to API
curl -v -H "Content-Type:application/json" -H "AUTH-TOKEN:$TOKEN" -d "$JSON" https://www.mindergas.nl/api/gas_meter_readings
The problem is in the line to extract the Counter of the gassensor with Idx 734in Domoticz:

curl -s "http://127.0.0.1:8084/json.htm?type=devices&rid=734" | jq '.result[0].Counter'| tr -d '"'

The result is: 693.927m3 So it ends with the text m3 and that is the point!

How do I cut those last two characters out of the variable? I just need the value!

Thanks for your hint!
Synology with Domoticz build (V2024.7) in Docker
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Export of IDX to long

Post by waaren »

PieterS wrote: Friday 25 January 2019 23:57 Try to upload a counter of the gassensor from Domoticz to Mindergas.nl.
693.927m3 So it ends with the text m3 ; How do I cut those last two characters out of the variable? I just need the value!
Try this

Code: Select all

#!/bin/bash
#Token to authenicate with mindergas.nl
TOKEN=**************************
#fetch meterstand (use jq to parse JSON object correctly)
METERSTAND=`curl -s "http://127.0.0.1:8084/json.htm?type=devices&rid=734"  | jq '.result[0].Counter'| tr -d '"'`
METERSTAND=${METERSTAND::-2}
#Get OS date, and format it corectly.
NOW=$(date +"%Y-%m-%d")
#Build JSON by hand ;-)
JSON='{ "date":"'$NOW'", "reading":"'$METERSTAND'"  }'
#post using curl to API
curl -v -H "Content-Type:application/json" -H "AUTH-TOKEN:$TOKEN" -d "$JSON" https://www.mindergas.nl/api/gas_meter_readings
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
PieterS
Posts: 197
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Re: Export of IDX to long

Post by PieterS »

THANKS A LOT! You made my day! Upload succeeded.

I noticed a chance in the output of the call to fetch all data that belongs to a device as described in the text on the WIKI: https://www.domoticz.com/wiki/Mindergas.nl

There it says:
The script is explained as:

So if you only do on the cli of your pi you can find out what the actual JSON object is. Just do this:

curl -s "http://127.0.0.1:8080/json.htm?type=devices&rid=8"

It turns out that the object looks like this:

Code: Select all

{
  "5MinuteHistoryDays" : 7,
  "ActTime" : 1414866673,
  "AllowWidgetOrdering" : true,
  "DashboardType" : 0,
  "Latitude" : "52.135674",
  "Longitude" : "6.182462",
  "MobileType" : 0,
  "TempScale" : 1.0,
  "TempSign" : "C",
  "WindScale" : 1.0,
  "WindSign" : "m/s",
  "dontcachehtml" : true,
  "result" : [
     {
        "BatteryLevel" : 255,
        "Counter" : "128.865",
        "CounterToday" : "1.865 m3",
Probably the output changed in the last stable version: I use Domoticz V4.9700 on a Synology with DSM 6.2. Or the sensor is a bit different..

Anyway: Thanks a lot for your hint! It means word[-2:] # characters from the second-last (included) to the end :D
Synology with Domoticz build (V2024.7) in Docker
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest