Testing jinja macro
This commit is contained in:
51
blueprints/automation/homeassistant/test_macro.yaml
Normal file
51
blueprints/automation/homeassistant/test_macro.yaml
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
blueprint:
|
||||||
|
name: Test-Macro
|
||||||
|
description: Prova Jinja2 Macro
|
||||||
|
domain: automation
|
||||||
|
author: Tiziano Trabattoni
|
||||||
|
# input:
|
||||||
|
# window_sensor:
|
||||||
|
# name: Window Status
|
||||||
|
# description: Identifies the Window Sensor Device for Opened Status
|
||||||
|
# selector:
|
||||||
|
# entity:
|
||||||
|
# filter:
|
||||||
|
# - device_class: door
|
||||||
|
# domain: binary_sensor
|
||||||
|
|
||||||
|
variables:
|
||||||
|
recipient_list:
|
||||||
|
- notify.mobile_app_tiziano_iphone15pro
|
||||||
|
# - notify.mobile_app_emanuele_s24
|
||||||
|
evcharge_entity1_power_var: >-
|
||||||
|
{% from 'template_library.jinja' import getpower_id %}
|
||||||
|
{{ getpower_id('switch.evcharge_back') }}
|
||||||
|
|
||||||
|
triggers:
|
||||||
|
- trigger: mqtt
|
||||||
|
topic: zigbee2mqtt/Pulsante-01
|
||||||
|
payload: single
|
||||||
|
value_template: "{{ value_json['action'] }}"
|
||||||
|
id: Pulsante1-single
|
||||||
|
|
||||||
|
conditions: []
|
||||||
|
actions:
|
||||||
|
- choose:
|
||||||
|
- conditions:
|
||||||
|
- condition: trigger
|
||||||
|
id:
|
||||||
|
- p1-confort-light-on
|
||||||
|
- test_animation
|
||||||
|
sequence:
|
||||||
|
# Hereafter the attemped usage as variable initialization
|
||||||
|
- repeat: # send message to all recipient-list members
|
||||||
|
for_each: "{{ recipient_list }}"
|
||||||
|
sequence:
|
||||||
|
- action: "{{ repeat.item }}"
|
||||||
|
metadata: {}
|
||||||
|
data:
|
||||||
|
message: >-
|
||||||
|
"TEST -> >>{{ evcharge_entity1_power_var }}<<"
|
||||||
|
title: TEST TEST
|
||||||
|
|
||||||
|
mode: single
|
||||||
@@ -1,9 +1,27 @@
|
|||||||
{% macro getpower_id(evcharge_id) %}
|
{# This macro returns _power entity for a controlled plug device #}
|
||||||
|
{% macro getpower_id(evcharge_id) %}
|
||||||
{% set attrib_list = device_entities( device_id (evcharge_id ) ) %}
|
{% set attrib_list = device_entities( device_id (evcharge_id ) ) %}
|
||||||
{% for attrib in attrib_list %}
|
|
||||||
{% if ( attrib | regex_search('power$')) %}
|
{% for attrib in attrib_list -%}
|
||||||
{{ attrib }}
|
{% if ( attrib | regex_search('power$')) -%}
|
||||||
{% endif %}
|
{{ attrib }}
|
||||||
{% endfor %}
|
{%- endif %}
|
||||||
{% endmacro %}
|
{%- endfor %}
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
|
||||||
|
{########################################################################}
|
||||||
|
|
||||||
|
{# This macro returns _energy entity for a controlled plug device #}
|
||||||
|
|
||||||
|
{% macro getenergy_id(evcharge_id) %}
|
||||||
|
{% set attrib_list = device_entities( device_id (evcharge_id ) ) %}
|
||||||
|
|
||||||
|
{% for attrib in attrib_list -%}
|
||||||
|
{% if ( attrib | regex_search('energy$')) -%}
|
||||||
|
{{ attrib }}
|
||||||
|
{%- endif %}
|
||||||
|
{%- endfor %}
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user