Temperature read out Pi without Domoticz

Moderator: leecollings

Post Reply
Cubic
Posts: 3
Joined: Sunday 31 January 2016 15:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.35.30
Location: Netherlands
Contact:

Temperature read out Pi without Domoticz

Post by Cubic »

Hello,

I want to read out the system temperature of my second Pi without install Domoticz on it.
Can anyone tell me if this is possible ?
And if the answer is yes, how ;)
paulvha
Posts: 40
Joined: Friday 29 January 2016 16:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Temperature read out Pi without Domoticz

Post by paulvha »

try : /opt/vc/bin/vcgencmd measure_temp
Cubic
Posts: 3
Joined: Sunday 31 January 2016 15:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.35.30
Location: Netherlands
Contact:

Re: Temperature read out Pi without Domoticz

Post by Cubic »

Thanks Paul

What I want is read the temperature from the second Pi in Domoticz installed on the first Pi.
But without install Domoticz on the second Pi
Mozart
Posts: 39
Joined: Monday 19 January 2015 14:35
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Temperature read out Pi without Domoticz

Post by Mozart »

I have this implemented. Here is what I did (feel free to optimize this :D ):
1. Install python on the second pi.
2. create a file e.g. temp.py with the following content:

Code: Select all

#!/usr/bin/env python

import tornado.ioloop
import tornado.web
import os

class MainHandler(tornado.web.RequestHandler):
    def getCPUtemperature( self ):
        res = os.popen('vcgencmd measure_temp').readline()
        return(res.replace("temp=","").replace("'C\n",""))

    def get(self):
        self.write( "%s" % ( self.getCPUtemperature() ) )

application = tornado.web.Application([
    (r"/", MainHandler),
])

if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()
The last line of the code shows the port number that is used. Start this code with:
python temp.py
Now use a browser to connect to the ip or name of your second pi on port 8.8.8.8, e.g.:
http://192.168.254.9:8888/
You should get a page with only the temperature, if this is showing the temp you have to solve this first.

To autostart this script at every boot you should create a script in /etc/init.d/ to make that work. There are examples on the internet how to do that, if you cannot get it working I will paste my /etc/init.d/ script for this.

Next, add a dummy temperature device in Domoticz. Go to the list of devices and make an note of the device number, we will need this later.
Past the following code to a script in e.g. /home/pi/domoticz/scripts (PI with Domoticz) and name it something like get-pi-temp.sh:

Code: Select all

#!/bin/bash

#replace with your Device IDX you found in the previous step.
SecondPi=44

#Internal temperature SecondPI
TEMP=$(curl http://<name or IP of your second PI:8888)
curl --connect-timeout 60 "http://localhost:8080/json.htm?type=command&param=udevice&idx=$PiZolder&nvalue=0&svalue=$TEMP"
Make sure that you get the details right.
Make the script executable with:

Code: Select all

chmod +x /home/pi/domoticz/scripts/get-pi-temp.sh
I use Cron to run this script every 5 minutes. Update your local cron on the first PI with these commands:
type: crontab -e (as user pi)
add this to the end of the file:

Code: Select all

*/5 * * * * /home/pi/domoticz/scripts/get-pi-temp.sh >/dev/null 2>&1
Now you should get a new temperature reading every 5 minutes in your Domoticz. Works for me, I have do this to retrieve the temp of 2 PI's that do not have Domoticz. On 1 PI I also connected 3 ds18b20 probes connected to the GPIO of that PI and pass them in a similar way to Domoticz.

Good luck!
Raspberry 3
Aeon Labs Z-Wave Stick Series 2 - RFLink USB Gateway
Z-Wave switches
433 MHz Temperature + Humidity sensors
Philips Hue Lights
Mi-Light WiFi Bridge + RGBW Controllers
Cubic
Posts: 3
Joined: Sunday 31 January 2016 15:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.35.30
Location: Netherlands
Contact:

Re: Temperature read out Pi without Domoticz

Post by Cubic »

Thank you for the script and the explanation
erigoth
Posts: 1
Joined: Monday 05 September 2016 21:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Temperature read out Pi without Domoticz

Post by erigoth »

Hello Mozart,

you wrote:
Mozart wrote: To autostart this script at every boot you should create a script in /etc/init.d/ to make that work. There are examples on the internet how to do that, if you cannot get it working I will paste my /etc/init.d/ script for this.
I've tried to get it to work in many ways:
1. @reboot in crontab
2. added bashscript to /etc/init.d
3. created a service for the bash script

the script starts, it just shows a blank page on the 8888 port...
when I kill the script and start it manually it works perfect but it wont start normally on reboot.

could you please share your script with me?

Hope you can help me.

greets,

Erigoth
Mozart
Posts: 39
Joined: Monday 19 January 2015 14:35
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Temperature read out Pi without Domoticz

Post by Mozart »

erigoth wrote:Hello Mozart,

you wrote:
Mozart wrote: To autostart this script at every boot you should create a script in /etc/init.d/ to make that work. There are examples on the internet how to do that, if you cannot get it working I will paste my /etc/init.d/ script for this.
I've tried to get it to work in many ways:
1. @reboot in crontab
2. added bashscript to /etc/init.d
3. created a service for the bash script

the script starts, it just shows a blank page on the 8888 port...
when I kill the script and start it manually it works perfect but it wont start normally on reboot.

could you please share your script with me?

Hope you can help me.

greets,

Erigoth
Oops, missed this. Do you still need the script?
Raspberry 3
Aeon Labs Z-Wave Stick Series 2 - RFLink USB Gateway
Z-Wave switches
433 MHz Temperature + Humidity sensors
Philips Hue Lights
Mi-Light WiFi Bridge + RGBW Controllers
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: Temperature read out Pi without Domoticz

Post by stlaha2007 »

As the first reply already mentioned use the raspbian supplied tools.... In the following script it reads the temperature of the pi and pushes it into domoticz and only requires the idx for the tempsensor within domoticz.

Run it with cron every 5 minutes like:
*/5 * * * * /home/pi/scripts/get_temp.sh 221

Script placed in /home/pi/scripts/get_temp.sh:

Code: Select all

#!/bin/bash
Current_Temp=$(/opt/vc/bin/vcgencmd measure_temp | cut -c6-9)
IDX=$1

echo $Current_Temp

curl -s "http://domoticz.ip.address:8080/json.htm?type=command&param=udevice&idx=$(echo $IDX)&nvalue=0&svalue=$(echo $Current_Temp)"

Also don't forget to: chmod +x /home/pi/scripts/get_temp.sh
So the script can be executed.

Sent from my K00C using Tapatalk
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest