Skip to content
View in the app

A better way to browse. Learn more.

Armbian Community Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Thermostat with orange Pi zero .

Featured Replies

I'm going to use an orange Pi zero to make a thermostat adjustable via lan; do you know how to point me to some easy to apply project?
I tried several projects, with ds1820b sensors and relais card for raspberry, but I have problems for example with the libraries RPi.GPIO because they do not match those OPi.GPIO.

I can currently turn the relays on and off with an android app or via terminal command.

  • Author

All right, now I do a clean installation and I start again, then I let you know. but I had decommented a few lines but the software did not start.Do you have any simple project to start from?

 

 

10 minutes ago, FRANK333 said:

Do you have any simple project to start from?

What do you mean ? Simple project to test this GPIO library ? Simple blinking LED on PA10 for example :

#!/usr/bin/python

import sys, time
from pyA20.gpio import gpio
from pyA20.gpio import port

gpio.init()

gpio.setcfg(port.PA10, gpio.OUTPUT)

while True:
	gpio.output(port.PA10, gpio.LOW)
	time.sleep(0.25)
	gpio.output(port.PA10, gpio.HIGH)
	time.sleep(0.25)

 

  • Author

I'm looking for a software that through a web page (or an android app) makes the Opi 0 work as a thermostat or at least a software sketch. As for the test program I'll try, but that library is for A20 I have an H2 will work ?

 

11 minutes ago, FRANK333 said:

but that library is for A20 I have an H2 will work ?

The link I've provided is a port of the pyA20 library to H3, and H2 is equivalent to H3.

12 minutes ago, FRANK333 said:

I'm looking for a software that through a web page

There is the HTTPServer library part of standard python, but you will have to learn a lot about it. I'm using it to produce Web interfaces.

  • Author

Martin, I installed the library and your test works. When I try to insert an if else line, the script doesn't work.

Spoiler

#!/usr/bin/env python

import os
import sys
if not os.getegid() == 0:
    sys.exit('Script must be run as root')


from time import sleep
from pyA20.gpio import gpio
from pyA20.gpio import port
from pyA20.gpio import connector

 

REL = port.PA0
maxTemp = 22

gpio.init()
gpio.setcfg(REL, gpio.OUTPUT)

while 1:
    #open the file for the sensor and read contents
    tempfile = open("/sys/bus/w1/devices/28-8000001f9605/w1_slave")
    thetext = tempfile.read()
    tempfile.close()
    #get the temperature
    tempdata = thetext.split("\n")[1].split(" ")[9]
    temperature = float(tempdata[2:])
    temperature = temperature / 1000
    #print out the temperature
    print temperature
    #switch the relays if temperature above maxTemp

while True:
       if temperature > maxTemp:
        gpio.output(REL, 0)

       else:
        gpio.output(REL, 1)

What's wrong? I don't know anything about Python ,I'm sorry.

1 hour ago, FRANK333 said:

What's wrong? I don't know anything about Python ,I'm sorry.

Indentation of line of code is important in Python !

Seeing your code above, the second "while" is not indented, so it never been executed since outside of the first one.

Lets rewrite your code here without second "while", since it is useless, but adding a delay of 30 seconds :

 

bad spoiler ...

 

 

#!/usr/bin/env python

import os
import sys
if not os.getegid() == 0:
    sys.exit('Script must be run as root')


from time import sleep
from pyA20.gpio import gpio
from pyA20.gpio import port
from pyA20.gpio import connector

 

REL = port.PA0
maxTemp = 22

gpio.init()
gpio.setcfg(REL, gpio.OUTPUT)

while 1:
    #open the file for the sensor and read contents
    tempfile = open("/sys/bus/w1/devices/28-8000001f9605/w1_slave")
    thetext = tempfile.read()
    tempfile.close()
    #get the temperature
    tempdata = thetext.split("\n")[1].split(" ")[9]
    temperature = float(tempdata[2:])
    temperature = temperature / 1000
    #print out the temperature
    print temperature
    #switch the relays if temperature above maxTemp

    if temperature > maxTemp:
        gpio.output(REL, 0)

    else:
        gpio.output(REL, 1) 

    sleep(30)

[/spoiler]

 

I've not tested it, but it should now work ...

 

  • Author

here is the error it returns, it seems that I can't find the variable maxTemp, and yet I defined it with       maxTemp = 22

 

root@orangepizero:~# python test.py
  File "test.py", line 32
    if temperature > maxTemp:
                            ^
IndentationError: unindent does not match any outer indentation level
root@orangepizero:~# python -m tabnanny test.py
'test.py': Indentation Error: unindent does not match any outer indentation level (<tokenize>, line 32)
root@orangepizero:~#

 

 

  • Author

Okay Martin I solved was just a tabulation problem as I could tell from your example. Now the rudimentary thermostat works, I would like to make sure that it remains in operation as a daemon, insert different temperatures at different times of the day, and finally make a decent GUI. But the road is uphill....

 

Spoiler

#!/usr/bin/env python
import os
import sys
if not os.getegid() == 0:
    sys.exit('Script must be run as root')

from time import sleep
from pyA20.gpio import gpio
from pyA20.gpio import port
from pyA20.gpio import connector

REL = port.PA0
maxTemp = 22

gpio.init()
gpio.setcfg(REL, gpio.OUTPUT)
#gpio.output(REL, 1)
while 1:
    #open the file for the sensor and read contents
    tempfile = open("/sys/bus/w1/devices/28-8000001f9605/w1_slave")
    thetext = tempfile.read()
    tempfile.close()
    #get the temperature
    tempdata = thetext.split("\n")[1].split(" ")[9]
    temperature = float(tempdata[2:])
    temperature = temperature / 1000
    #print out the temperature
    print temperature
    #switch the relays if temperature above maxTemp
    if temperature > maxTemp:
            gpio.output(REL, 0)
    else:
            gpio.output(REL, 1)
sleep(1)

 

  • Author

ok I corrected and added the lines to make the script a daemon, I noticed however that if I kill the script (kill 1234) or if I block the OPI0 the relays card remains in the last state in which it is, how could you do to reset it to off?

Spoiler

#!/usr/bin/env python
import os
import sys
if not os.getegid() == 0:
    sys.exit('Script must be run as root')

from time import sleep
from daemonize import Daemonize
from pyA20.gpio import gpio
from pyA20.gpio import port
from pyA20.gpio import connector

REL = port.PA0
maxTemp = 22

gpio.init()
gpio.setcfg(REL, gpio.OUTPUT)

pid = "/tmp/test.pid"

def main():
    while 1:
        #open the file for the sensor and read contents
        tempfile = open("/sys/bus/w1/devices/28-8000001f9605/w1_slave")
        thetext = tempfile.read()
        tempfile.close()
    #get the temperature
        tempdata = thetext.split("\n")[1].split(" ")[9]
        temperature = float(tempdata[2:])
        temperature = temperature / 1000
    #print out the temperature
        print temperature
    #switch the relays if temperature above maxTemp
        if temperature > maxTemp:
                gpio.output(REL, 0)
        else:
                gpio.output(REL, 1)
        sleep(1)

daemon = Daemonize(app="test_app", pid=pid, action=main)
daemon.start()

 

  • Author

I tried to add at the end of the script, these 4 lines :

 

def signal_term_handler(signal, frame):

    print 'got SIGTERM'

    sys.exit(0)

signal.signal(signal.SIGTERM, signal_term_handler)

 

but the relays maintain the status, even after the kill command.

Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.