Passing system temp to Domoticz using a bash script Topic is solved

All kinds of 'OS' scripts

Moderator: leecollings

Post Reply
User avatar
pgielen
Posts: 90
Joined: Monday 18 February 2019 14:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Boxmeer
Contact:

Passing system temp to Domoticz using a bash script

Post by pgielen »

I am trying to read the system temperature from my RPi and send it to Domoticz, using the following bash script:

Code: Select all

#! /bin/sh
temp=$(vcgencmd measure_temp | egrep -o '[0-9]*\.[0-9]*')
echo "System temperature: $temp"
url="http://192.168.1.52:8080/json.htm?type=command&param=udevice&idx=571&nvalue=0&svalue=$temp"
echo "$curl"
curl "$url"
Lines 3 and 5 are only there for testing if the values passed on to the url are correct.

However, this does not work; curl answers (3) URL using bad/illegal format or missing URL, because it apparently expects double quotes arount the url (if I directly type in something like: curl "http://192.168.1.52:8080/json.htm?type= ... &svalue=77" in the cli, the value is passed on to Domoticz without problems).

Changing line 4 to:

Code: Select all

url="\"http://192.168.1.56:8088/json.htm?type=command&param=udevice&idx=571&nvalue=0&svalue=$temp\""
does not work either, because the url string will get a leading double quote, but the double quote at the end of the string still gets lost for some reason.

I tried the same with wget in stead of curl, with the same results...

Is there another way to pass such a value from bash to Domoticz or should I switch to PHP or Python for this relatively simple task?
https://robothuis.nl, RPi4B, RFXCOM XL, Aeotec Z-Stick, ESP Easy, Weatherstation, several switches and sensors, Ikea Trädfri, Philips Hue, Foscam, Reolink, Lyric T6, Ring
User avatar
felix63
Posts: 244
Joined: Monday 07 December 2015 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Gouda
Contact:

Re: Passing system temp to Domoticz using a bash script

Post by felix63 »

did you try this?

Code: Select all

curl $url
User avatar
pgielen
Posts: 90
Joined: Monday 18 February 2019 14:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Boxmeer
Contact:

Re: Passing system temp to Domoticz using a bash script

Post by pgielen »

felix63 wrote: Saturday 22 August 2020 12:03 did you try this?

Code: Select all

curl $url
Yes, same problem
https://robothuis.nl, RPi4B, RFXCOM XL, Aeotec Z-Stick, ESP Easy, Weatherstation, several switches and sensors, Ikea Trädfri, Philips Hue, Foscam, Reolink, Lyric T6, Ring
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Passing system temp to Domoticz using a bash script

Post by waaren »

pgielen wrote: Saturday 22 August 2020 11:31 I am trying to read the system temperature from my RPi and send it to Domoticz
I normally use the bash shell.
sh is behaving different.

I tested below script and it does the job.

Code: Select all

#!/bin/bash
temp=$(vcgencmd measure_temp | egrep -o '[0-9]*\.[0-9]*')
echo "System temperature: $temp"
url="http://192.168.1.52:8080/json.htm?type=command&param=udevice&idx=571&nvalue=0&svalue=$temp"
echo $url
curl $url
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
pgielen
Posts: 90
Joined: Monday 18 February 2019 14:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Boxmeer
Contact:

Re: Passing system temp to Domoticz using a bash script

Post by pgielen »

Yes it does. Remarkably enough the problem were -once more- CRLF characters in the script. I dit not see this coming, since the CR's ended up not in the variable names, but in the values of the variables $temp and $url. No idea how this can happen, but after I removed the CR from the end of every line in the script, the problem was solved.
https://robothuis.nl, RPi4B, RFXCOM XL, Aeotec Z-Stick, ESP Easy, Weatherstation, several switches and sensors, Ikea Trädfri, Philips Hue, Foscam, Reolink, Lyric T6, Ring
User avatar
gizmocuz
Posts: 2350
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Passing system temp to Domoticz using a bash script

Post by gizmocuz »

Could you try beta 12268, when you add the motherboard hardware to your domoticz (from the hardware setup page), you should see your motherboard temperature. (double check if accept new hardware/devices is enabled in your settings)
(I think this should also with with previous beta's already as It's working on my RPi4)
Quality outlives Quantity!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest