peted-davis / WeatherFlow_PiConsole

Raspberry Pi Python console for WeatherFlow Tempest and Smart Home Weather Stations
GNU General Public License v3.0
155 stars 20 forks source link

Sample Code For Indoor Temp #39

Open jjkirby opened 2 years ago

jjkirby commented 2 years ago

I have a DHT22 Temp sensor. I am new to Python and I was wondering if there is any sample code to show how to incorporate those readings for indoor Temp/humidity?

I can probably write the function call but what pseudo-code do you use to call that function in main.py would be helpfully. Working example (sample) would be awesome!

Follow-up:

I wrote a sample python script which returns temperature (and humidity):

import board
import adafruit_dht

def gettemp():
    dhtDevice = adafruit_dht.DHT22(board.D4)
    return  dhtDevice.temperature  * (9 / 5) + 32

This works fine to test the sensor working

for the main.py I call:


# Indoor Temperature
  Clock.schedule_interval(partial(temp.gettemp, self.Obs), 10.0)

The function looks like this:

import board
import adafruit_dht

dhtDevice = adafruit_dht.DHT22(board.D4)

def gettemp(obs):

        obs['inTemp'][0] = str(dhtDevice.temperature * (9 / 5) + 32)
        obs['inTemp'][1] = '\u00b0' + "F"

        return obs

I even tried to manually set via:

self.Obs['inTemp'][0] = "25.0"
self.Obs['inTemp'][1] = '\u00b0' + "F"

I never see the update? A Kivy problem?

andy-cooper commented 2 years ago

Have a look at my fork - I integrated the Ecobee thermostat with this so that I can see the indoor temperature and current thermostat settings.

In particular, look at ecobee.py:L120 for the location where most of the work to retrieve and display the temperature happens. It runs as a separate thread that never exits; the thread is started in main.py:L426

All works fine for me ...