add heater control

This commit is contained in:
Ingolf Wagner 2021-03-16 22:14:50 +01:00
parent dc1a70d94f
commit 671ab04997
No known key found for this signature in database
GPG key ID: 76BF5F1928B9618B
5 changed files with 26 additions and 12 deletions

View file

@ -6,6 +6,7 @@ in {
#./home-assistant/mpd.nix
#./home-assistant/timer.nix
./home-assistant/light-control.nix
./home-assistant/heater-control.nix
./home-assistant/chaospott.nix
./home-assistant/kodi.nix
./home-assistant/mqtt.nix

View file

@ -0,0 +1,16 @@
{ lib, pkgs, config, ... }: {
users.users.heater-control = { };
systemd.services.heater-control = {
enable = true;
wantedBy = [ "multi-user.target" ];
serviceConfig = { User = "heater-control"; };
script =
let myPython = pkgs.python3.withPackages (ps: with ps; [ paho-mqtt ]);
in ''
${myPython}/bin/python ${<mqtt/heater.py>}
'';
};
}

View file

@ -55,13 +55,13 @@ def publish_heater(client, temperature=10):
def publish_heater_depending_on_scene(client):
if scene == "night":
publish_heater(client, 10)
publish_heater(client, 12)
elif scene == "default":
publish_heater(client, 26)
elif scene == "outside":
publish_heater(client, 8)
publish_heater(client, 10)
else:
publish_heater(client, 8)
publish_heater(client, 10)
def loop_thread(client):

View file

@ -1,20 +1,15 @@
{ pkgs ? import <nixpkgs> { } }:
let
myPython = pkgs.python3.withPackages (python-packages:
with python-packages; [
paho-mqtt
]);
myPython = pkgs.python3.withPackages
(python-packages: with python-packages; [ paho-mqtt ]);
startServer = pkgs.writers.writeBashBin "start-server" ''
${myPython}/bin/python ./main.py
${myPython}/bin/python ./heater.py
'';
in pkgs.mkShell {
buildInputs = with pkgs; [
myPython
startServer
];
buildInputs = with pkgs; [ myPython startServer ];
}

View file

@ -82,6 +82,8 @@ let
pkgs.file = toString ./pkgs;
assets.file = toString ./assets;
mqtt.file = toString ./mqtt;
nix-writers.git = {
url = "https://cgit.krebsco.de/nix-writers/";
ref = (ops.importJson ./.nix-writers.json).rev;