Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {# VAR #}
- {% set on_sensors = {
- "cd71f96a0d0e412bba41e91e3866ee07": ["Havelåge", "3C003A", "door"],
- "f1fe358686d14a9f916ffaf77d7d2fde": ["Hoveddør", "C0E3DA", "door"]
- } %}
- {% set on_off_sensors = {
- "4b03ffb918314900b4b59eed108c1960": ["Dobbelt terrassesdør", "45400", "A", "E", "door"],
- "48d246efd72c4485afca819baa59051b": ["Soveværelse vindue", "B1C40", "A", "E", "window"],
- "7e3185c4aef2445a981583b736273364": ["Pigernes stue vindue", "AFF70", "A", "E", "window"],
- "3ff715ed48204fce967b67fdc70fa692": ["Nathalies vindue", "B2B10", "A", "E", "window"],
- "2a3dec1038084981b6f786b54a28c17b": ["Cornelies vindue", "181F0", "A", "E", "window"]
- } %}
- {# CON #}
- {% set state_topic = "tele/tasmota/RESULT" %}
- {% set value_template = "{{ value_json.RfReceived.Data }}" %}
- {% set off_delay = 15 %}
- {# MACRO #}
- {% macro private_device(sensor) -%}
- {{ "PRIVATE "~on_off_sensors[sensor][0] if on_off_sensors[sensor][4] == "window" else on_off_sensors[sensor][0]}}
- {%- endmacro %}
- {%- macro entity_name(name) -%}
- {% set name = name.lower() %}
- {%- set name = name.replace("æ", "a") %}
- {%- set name = name.replace("ø", "o") %}
- {%- set name = name.replace("å", "a") %}
- {%- set name = name.replace(" ", "_") -%}
- {{ name }}
- {%- endmacro %}
- {% macro sensor_value(sensor_id) -%}
- {{ "{{ states('"~sensor_id~"') }}" }}
- {%- endmacro %}
- {% macro sensor_icon(sensor_id) -%}
- {{ "mdi:window-{{ 'open' if is_state('"~sensor_id~"', 'on') else 'closed' }}-variant" }}
- {%- endmacro %}
- windows_doors:
- group:
- open_close_sensors:
- name: "Vinduer og døre med åbn/luk sensor"
- icon: mdi:window-closed-variant
- all: true
- entities:
- {%- for sensor in on_off_sensors %}
- {%- set entity_id = entity_name (on_off_sensors[sensor][0]) %}
- {%- set sensor_id = "binary_sensor.private_"~entity_id %}
- - binary_sensor.{{ entity_id }}
- {%- endfor %}
- binary_sensor:
- {%- for sensor in on_sensors %}
- - platform: mqtt
- name: "{{ on_sensors[sensor][0] }}"
- unique_id: {{ sensor }}
- device_class: {{ on_sensors[sensor][2] }}
- state_topic: "{{ state_topic }}"
- value_template: "{{ value_template }}"
- payload_on: "{{ on_sensors[sensor][1] }}"
- off_delay: {{ off_delay }}
- {% endfor %}
- {%- for sensor in on_off_sensors %}
- - platform: mqtt
- name: "{{ private_device(sensor) }}"
- unique_id: {{ 'private_' if on_off_sensors[sensor][4] == "window"}}{{ sensor }}
- device_class: {{ on_off_sensors[sensor][4] }}
- state_topic: "{{ state_topic }}"
- value_template: "{{ value_template }}"
- payload_on: "{{ on_off_sensors[sensor][1] }}{{ on_off_sensors[sensor][2] }}"
- payload_off: "{{ on_off_sensors[sensor][1] }}{{ on_off_sensors[sensor][3] }}"
- {% endfor %}
- - platform: template
- sensors:
- {%- for sensor in on_off_sensors if on_off_sensors[sensor][4] == "window" %}
- {%- set entity_id = entity_name (on_off_sensors[sensor][0]) %}
- {%- set sensor_id = "binary_sensor.private_"~entity_id %}
- {{ entity_id }}:
- friendly_name: "{{ on_off_sensors[sensor][0] }}"
- unique_id: {{ sensor }}
- device_class: window
- value_template: "{{ sensor_value(sensor_id) }}"
- icon_template: "{{ sensor_icon(sensor_id) }}"
- {% endfor %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement