summaryrefslogtreecommitdiffstats
path: root/makefu/2configs/home/ham/sensor
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2022-09-23 23:41:30 +0200
committermakefu <github@syntax-fehler.de>2022-09-23 23:41:30 +0200
commit3e8f855f60dfa5bf56ab3a1d1a54e0accccbd618 (patch)
tree85674a93388edfb7a0646b46aafc18d64d7aa0c6 /makefu/2configs/home/ham/sensor
parent2dfde5dc6d37fb5bab8a1b658cfe7e5b21f5a2f4 (diff)
ma ham: update
Diffstat (limited to 'makefu/2configs/home/ham/sensor')
-rw-r--r--makefu/2configs/home/ham/sensor/dwd.nix8
-rw-r--r--makefu/2configs/home/ham/sensor/pollen.nix65
2 files changed, 73 insertions, 0 deletions
diff --git a/makefu/2configs/home/ham/sensor/dwd.nix b/makefu/2configs/home/ham/sensor/dwd.nix
new file mode 100644
index 000000000..c1d55d03c
--- /dev/null
+++ b/makefu/2configs/home/ham/sensor/dwd.nix
@@ -0,0 +1,8 @@
+{
+ services.home-assistant.config.sensor =
+ [
+ { platform = "dwd_weather_warnings";
+ region_name = "Stadt Stuttgart";
+ }
+ ];
+}
diff --git a/makefu/2configs/home/ham/sensor/pollen.nix b/makefu/2configs/home/ham/sensor/pollen.nix
new file mode 100644
index 000000000..d95c199bf
--- /dev/null
+++ b/makefu/2configs/home/ham/sensor/pollen.nix
@@ -0,0 +1,65 @@
+{ pkgs, lib, ... }:
+with lib;
+let
+ region = "112";
+ types = [
+ "Erle"
+ "Beifuss"
+ "Ambrosia"
+ "Birke"
+ "Esche"
+ "Hasel"
+ "Graeser"
+ "Roggen"
+ ];
+ gen_tomorrow_sensor = type: {
+ name = "dwd_pollenbelastung_${toLower type}_tomorrow";
+ value = {
+ icon_template = "mdi:grass";
+ friendly_name = "${type} Morgen";
+ value_template = "{{ state_attr('sensor.dwd_pollenbelastung_${toLower type}', 'tomorrow') }}";
+ };
+ };
+ gen_sensor = type: {
+ name = "dwd_pollenbelastung_${toLower type}";
+ value = {
+ icon_template = "mdi:tree-outline";
+ friendly_name = type;
+ value_template = ''
+ {% set dwd_state = state_attr('sensor.dwd_pollenbelastung_stuttgart', '${type}')['today'] %}
+ {% if dwd_state == "3" %}6{% elif dwd_state == "2-3"%}5{% elif dwd_state == "2"%}4{% elif dwd_state == "1-2"%}3{% elif dwd_state == "1"%}2{% elif dwd_state == "0-1"%}1{% else %}0{% endif %}
+ '';
+ attribute_templates.today = ''
+ {% set dwd_state = state_attr('sensor.dwd_pollenbelastung_stuttgart', '${type}')['today'] %}
+ {% if dwd_state == "3" %}6{% elif dwd_state == "2-3"%}5{% elif dwd_state == "2"%}4{% elif dwd_state == "1-2"%}3{% elif dwd_state == "1"%}2{% elif dwd_state == "0-1"%}1{% else %}0{% endif %}
+ '';
+ attribute_templates.tomorrow = ''
+ {% set dwd_state = state_attr('sensor.dwd_pollenbelastung_stuttgart', '${type}')['tomorrow'] %}
+ {% if dwd_state == "3" %}6{% elif dwd_state == "2-3"%}5{% elif dwd_state == "2"%}4{% elif dwd_state == "1-2"%}3{% elif dwd_state == "1"%}2{% elif dwd_state == "0-1"%}1{% else %}0{% endif %}
+ '';
+ # -1 == unknown
+ #attribute_templates.dayafter = ''
+ # {% set dwd_state = state_attr('sensor.dwd_pollenbelastung', '${type}')['dayafter_to'] %}
+ # {% if dwd_state == "3" %}6{% elif dwd_state == "2-3"%}5{% elif dwd_state == "2"%}4{% elif dwd_state == "1-2"%}3{% elif dwd_state == "1"%}2{% elif dwd_state == "0-1"%}1{% elif dwd_state == "-1"%}-1{% else %}0{% endif %}
+ #'';
+ };
+ };
+in
+ {
+ services.home-assistant.config.sensor = [
+ {
+ platform = "rest";
+ scan_interval = 3600;
+ name = "DWD Pollenbelastung Stuttgart";
+ resource = "https://opendata.dwd.de/climate_environment/health/alerts/s31fg.json";
+ json_attributes_path = "$..content[?(@.partregion_id==${region})].Pollen";
+ json_attributes = types;
+ value_template = "{{ value_json.last_update }}";
+ }
+ {
+ platform = "template";
+ sensors = (listToAttrs (map gen_sensor types)) //
+ (listToAttrs (map gen_tomorrow_sensor types)) ;
+ }
+ ];
+}