Hi,
Currently I have a problem.
I have a couple of ESP Easy nodemcus running. They can send their uptime to pimatic and the EspEasy do that in minutes. So I have a variable:
{
"name": "cv-control-uptime",
"value": 7601
},
So if I do on the linux command line something like:
up=7601
printf '%d days %02d hours %02d minutes' $((up/1440)) $((up%1440/60)) $((up%60))
5 days 06 hours 41 minutes
So based on my variable I created a device:
{
"id": "cv-control-uptime",
"name": "cv-control-uptime",
"class": "ShellSensor",
"attributeName": "time",
"attributeType": "string",
"attributeAcronym": "uptime cv-control",
"command": "printf '%d days %02d hours %02d minutes' $((cv-control-uptime/1440)) $((cv-control-uptime%1440/60)) (($cv-control-uptime%60))",
"interval": 60000
}
I can’t get this work. No matter which quotes, backslashes and so forth I use. I always get 0 days 00 hours 00 minutes
.
So I tried a second solution (actually because I can’t get this to work): I created a second variable like cvcontroluptcalc
and change the command in my ShellSensor to
`“command”: "/home/harryvanderwolf/pimatic/scripts/esp-uptime.sh cvcontroluptcalc cv-control-uptime"
and write that script esp-uptime.sh like
#!/bin/bash
VARNAME=$1 # Variable to post back
UPTIME=$2 # value (=calculated) to post back
CALCULATED=$(printf '%d days %02d hours %02d minutes' $((UPTIME/1440)) $((UPTIME%1440/60)) $((UPTIME%60)))
curl -s -X PATCH --header "Content-Type:application/json" --data '{"type": "value", "valueOrExpression": "'$CALCULATED'"}' --user "$USERNAME:$PASSWORD" http://localhost/api/variables/$VARNAME > /dev/null
When I run that script from the command line or from my shellsensor I get:
error [pimatic]: Error on incoming http request to /api/variables/cvcontroluptcalc: Unexpected end of input
This script is a 100% copy of another “calculate time” script apart from the fact that the calculation is different. If I add an echo $CALCULATED
the uptime is nicely echoed. The other script works fine.
I really don’t understand.