Hi,
For the key “value” in the service “var.set” I want to use a template using Jinja.
Unfortunately it is formatting the code as a string inserting \n etc. which makes it unreadable.
It seems that this behaviour is dependent on the service.
is there a workaround?
- service: var.set
alias: Arbeitspreis Wärme
metadata: {}
data:
value: "{# Arbeitspreis ermitteln (einmal im Monat) #}\n{% set preis = ({ \n \"2024.7.1\": 112.95,\n \"2024.10.1\": 112.95\n }) %}\n\n{% set ns = namespace(break=false) %} {% set ns = namespace(fee=preis[\"2024.7.1\"]) %} {% set now = now()\t%} {% set day = now.year |string + '.' + now.month |string + '.1'%} {% for key in preis %}\n {% if not ns.break %}\n {% if day <= key %}\n {% set ns.fee = preis[key] %}\n {% set ns.break = true %}\n {% endif %}\n {% endif %}\n{% endfor %} \n{{ ns.fee }}"
target:
entity_id: var.arbeitspreis_warme
I also tried with a different syntax
- service: var.set
metadata: {}
data:
value_template: "{% set tibber_fee = ({ \n \"2024.7.1\": 3.35*1.19,\n \"2024.10.1\": 3.35*1.19\n }) %}\n{% set net_metering_fee = ({ \n \"2024.7.1\": (0.0459 + 0.1152)*1.19,\n \"2024.10.1\": (0.0459 + 0.1152)*1.19\n }) %}\n{# Calculate tibber fea per minute #}\n \n{% set ns = namespace(break=false) %} {% set ns = namespace(fee=tibber_fee[\"2024.7.1\"]) %} {% set now = now()\t%} {% set day = now.year |string + '.' + now.month |string + '.1'\t%} {% for key in tibber_fee %}\n {% if not ns.break %}\n {% if day <= key %}\n {% set ns.fee = tibber_fee[key] %}\n {% set ns.break = true %}\n {% endif %}\n {% endif %}\n{% endfor %} \n{% set no_days_in_month = ((now.replace(day=1) + timedelta(days = 32)).replace(day=1) -timedelta(days=1)).day %} {% set tibber = ns.fee/(no_days_in_month *24*60) %}\n{# Calculate network and measurement service fea per minute #} {% set ns.break = false %} {% for key in net_metering_fee %}\n {% if not ns.break %}\n {% if day <= key %}\n {% set ns.fee = net_metering_fee[key] %}\n {% set ns.break = true %}\n {% endif %}\n {% endif %}\n{% endfor %} {% set network = ns.fee / (24*60) %} {{network + tibber }}"
entity_id: var.minutliche_grundgebuhr_bezug
alias: Minütliche Grundgebühr Tibber und Netz- und Messstellen
type or paste code here
but no luck