Skip to content

Sample Code For Indoor Temp #39

Open

Description

@jjkirby

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?

Activity

  1. andrea-cooper commented on Dec 27, 2021

    @andrea-cooper

    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 ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions