Created
October 10, 2018 22:50
-
-
Save Keyes/7220a54c70917a814a6a9146b3118440 to your computer and use it in GitHub Desktop.
Very simple thermostat written in Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sensor = require('ds1820-temp'); | |
const gpio = require('rpi-gpio'); | |
const CHECK_INTERVAL = 30 * 1000 // every 30s | |
const GPIO_PORT = 13; | |
const SENSOR_ID = '0000067bdac4'; | |
setInterval(checkTemperature, CHECK_INTERVAL); | |
async function checkTemperature() { | |
const currentHour = (new Date()).getHours(); | |
const sensorData = await sensor.readDevice(SENSOR_ID); | |
const currentTemperatureCelsius = sensorData.value; | |
let targetTemperatureCelsius = 16; | |
if ( | |
(currentHour > 7 && currentHour < 9) || | |
(currentHour > 18 && currentHour < 23) | |
) { | |
targetTemperatureCelsius = 22; | |
} | |
gpio.write(GPIO_PORT, currentTemperatureCelsius < targetTemperatureCelsius); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment