Thanks for reply,
For me it doesn’t work, I removed from hacs lovelace gen restarted … then reinstalled and restarted again but the error persists.
The version I have of lovelace gen is 6
As per the instruction in the issue - they haven’t made a release for the fix, so you need to change the version in HACS to ‘master’ so that it pulls the latest changes.
Nothing, even installing the master version. The error remains … do I have to do anything else?
thank you very much
That’s what got it over the line for me. I did replace all my files with the latest version in my process of trying to resolve this, which had some other fixes in it - not sure if that was related or not?
did you manually reinstall in hacs lovelace gen?
I manually downloaded the package from the Github repository and then overwrote the files through my HA’s samba share. That is what fixed it for me. I don’t think the fix has been fully committed to the repo yet so the “update” in HACs doesn’t work.
excellent, doing it by hand is back to work, thank you very much
Here is the lovelace gen fix / update for ease of use, just replace it with the file below thanks to petro …
lovelace gen already has the fix, here’s the code if you don’t want to wait. Replace the contents of config/custom_components/lovelace_gen/__init__.py
with:
import os
import logging
import json
import io
import time
from collections import OrderedDict
import jinja2
from homeassistant.util.yaml import loader
from homeassistant.exceptions import HomeAssistantError
_LOGGER = logging.getLogger(__name__)
def fromjson(value):
return json.loads(value)
jinja = jinja2.Environment(loader=jinja2.FileSystemLoader("/"))
jinja.filters['fromjson'] = fromjson
llgen_config = {}
def load_yaml(fname, secrets = None, args={}):
try:
ll_gen = False
with open(fname, encoding="utf-8") as f:
if f.readline().lower().startswith("# lovelace_gen"):
ll_gen = True
if ll_gen:
stream = io.StringIO(jinja.get_template(fname).render({**args, "_global": llgen_config}))
stream.name = fname
return loader.yaml.load(stream, Loader=lambda _stream: loader.SafeLineLoader(_stream, secrets)) or OrderedDict()
else:
with open(fname, encoding="utf-8") as config_file:
return loader.yaml.load(config_file, Loader=lambda stream: loader.SafeLineLoader(stream, secrets)) or OrderedDict()
except loader.yaml.YAMLError as exc:
_LOGGER.error(str(exc))
raise HomeAssistantError(exc)
except UnicodeDecodeError as exc:
_LOGGER.error("Unable to read file %s: %s", fname, exc)
raise HomeAssistantError(exc)
def _include_yaml(ldr, node):
args = {}
if isinstance(node.value, str):
fn = node.value
else:
fn, args, *_ = ldr.construct_sequence(node)
fname = os.path.abspath(os.path.join(os.path.dirname(ldr.name), fn))
try:
return loader._add_reference(load_yaml(fname, ldr.secrets, args=args), ldr, node)
except FileNotFoundError as exc:
_LOGGER.error("Unable to include file %s: %s", fname, exc);
raise HomeAssistantError(exc)
def _uncache_file(ldr, node):
path = node.value
timestamp = str(time.time())
if '?' in path:
return f"{path}&{timestamp}"
return f"{path}?{timestamp}"
loader.load_yaml = load_yaml
loader.SafeLineLoader.add_constructor("!include", _include_yaml)
loader.SafeLineLoader.add_constructor("!file", _uncache_file)
async def async_setup(hass, config):
llgen_config.update(config.get("lovelace_gen"));
return True
# Allow redefinition of node anchors
import yaml
def compose_node(self, parent, index):
if self.check_event(yaml.events.AliasEvent):
event = self.get_event()
anchor = event.anchor
if anchor not in self.anchors:
raise yaml.composer.ComposerError(None, None, "found undefined alias %r"
% anchor, event.start_mark)
return self.anchors[anchor]
event = self.peek_event()
anchor = event.anchor
self.descend_resolver(parent, index)
if self.check_event(yaml.events.ScalarEvent):
node = self.compose_scalar_node(anchor)
elif self.check_event(yaml.events.SequenceStartEvent):
node = self.compose_sequence_node(anchor)
elif self.check_event(yaml.events.MappingStartEvent):
node = self.compose_mapping_node(anchor)
self.ascend_resolver()
return node
yaml.composer.Composer.compose_node = compose_node
Whenever I make a manual change to the config file, Hacs disappears. Even with this it happened.
Did you do a full restart of home assistant, if yes i’m not sure what thats all about ? as it worked for me after scratching my head to find a solution to get it to work.
I downgraded homeassistant, then changed init.py and upgraded to version 2021.4.0. Now works. Thanks andie will5.
I installed the package from scratch, but my pop-ups are still not working. Even after the posted new version… I don’t get it, tried reinstalling everything but nothing works
Klogg, can you please tell what were breaking changes causing?
I’ve spent few more hours trying to find the problem in v1, I understood many things but I could not fix the issue anyway.
Maybe what you fixed in v2 is the same I should fix in V1.
I suspect that’s something related to getting input_number value to define duration, but I really can’t sort it out.
I’m not asking you to fix it for me, but I really need some help and tips, I’m stuck…
Edit: ok, now I’m quite sure that the problem is that concatenation part to read the duration from the input_number.
In log I see:
- Error while executing automation automation.irrigation_run_a_cycle_manually: Error rendering data template: TypeError: can only concatenate str (not “int”) to str
- Error while executing automation automation.irrigation_run_a_cycle_manually: Error rendering service name template: TypeError: can only concatenate str (not “int”) to str
I googled for that error and I found an old post wrote by you, related to the same error but in Dec 2019.
The error is the same, but the code already has ‘1’ as zone parameter.
I always keep HA up to date so for sure my problem is not exactly the same reported by you in '19, otherwise the program could not work till last autumn, but it must be strictly related to it.
Unfortunately I’m really not good in managing int, str, conversions, etc.
That concatenation is used in many places, so if Someone guides me in the correct way I should be able to fix it.
Current code giving error is, for example:
- condition: template
value_template: >
{% if is_state('input_boolean.cycle' + cycle + '_use_weather_adjustment', 'on') %}
{% set n = states('input_number.adjusted_cycle' + cycle + '_zone' + zone + '_duration') | int %}
{% else %}
{% set n = states('input_number.cycle' + cycle + '_zone' + zone + '_duration') | int %}
{% endif %}
{{ n != 0 }}
The script looks called in the right way:
- service: script.irrigation_irrigate_a_zone
data_template:
cycle: '{{ cycle }}'
zone: '1'
Good morning, I don’t know if it happens to you too but every morning I find this error which then disappears in the afternoon (or at least I noticed it a couple of times but I’ll check it again) returning to work perfectly. What could it be?
ButtonCardJSTemplateError: TypeError: Cannot read property 'state' of undefined in 'var statestr = (entity === undefined || entity.state === undefined) ? 'undefined' : entity.state; ...'
tap_action:
action: fire-dom-event
browser_mod:
command: popup
title: Irrigation Controller
hide_header: true
card:
type: vertical-stack
cards:
- type: markdown
content: >-
Enter the name of the sensor for your irrigation controller WiFi
signal strength.
Leave blank to reset to default.
style: |
ha-card {
font-family: {{ states('input_text.irrigation_ui_font_family') }};
font-size: 16px;
}
- type: entities
entities:
- entity: input_text.irrigation_external_sensor_controller_wifi
name: Sensor Name
- entity: input_number.irrigation_controller_offline_wait
name: Seconds To Wait When Offline
- type: section
style: |
ha-card {
font-family: {{ states('input_text.irrigation_ui_font_family') }};
}
- type: markdown
content: You can disable the switches to prevent irrigation while testing.
style: |
ha-card {
font-family: {{ states('input_text.irrigation_ui_font_family') }};
font-size: 16px;
}
- type: entities
entities:
- entity: input_boolean.irrigation_disable_switches
style: |
ha-card {
font-family: {{ states('input_text.irrigation_ui_font_family') }};
}
type: 'custom:button-card'
group_expand: false
hold_action:
action: none
double_tap_action:
action: none
layout: vertical
size: 30%
color_type: icon
show_name: true
show_state: true
show_icon: true
show_units: true
show_label: false
show_entity_picture: false
show_live_stream: false
card_size: 3
entity: sensor.esphome_irrigation_controller_wifi_signal
name: |
[[[
var statestr = (entity === undefined || entity.state === undefined) ? 'undefined' : entity.state;
var unit_om = (statestr != 'undefined' && entity.attributes.unit_of_measurement) ? entity.attributes.unit_of_measurement : '';
return 'Irrigation Controller' + ' (' + entity.state + ' ' + unit_om + ')'
]]]
icon: >-
[[[ return (entity === undefined || entity.state == 'unavailable') ?
'mdi:wifi-off' : 'mdi:wifi'; ]]]
state_display: '<elt><ha-icon icon=mdi:square-edit-outline></ha-icon></elt>'
styles:
grid:
- grid-template-areas: '"i n s"'
- grid-template-columns: 15% auto 5%
- grid-template-rows: 1fr
card:
- font-family: '[[[ return states[''input_text.irrigation_ui_font_family''].state ]]]'
- font-size: 15px
- padding: 0em 1.5em 0em 0em
- background: none
- box-shadow: none
name:
- justify-self: start
state:
- value: unavailable
styles:
icon:
- color: var(--accent-color)
- animation: blink 2s ease infinite
state:
- color: var(--accent-color)
- animation: blink 2s ease infinite
default_color: var(--primary-text-color)
color_off: var(--paper-item-icon-color)
color_on: var(--paper-item-icon-active-color)
lock:
enabled: false
duration: 5
unlock: tap
Hello, I managed to install everything correctly, but I needed to customize a little thing, I need to put a pump to turn on in some areas.
Its possible have the option under switch name?
Regards,
Hi @Robertofz1981,
you can do that in esphome.
I’ve managed to do it turning on the pump relay every time one valve/zone is turned on.
This is my configuration using one esp32, i don’t know what kind of switches you are using, but i think you can achieve the same result with your system.
In esphome u can do like these:
switch:
- platform: gpio
pin:
number: 18
inverted: True
name: Valvola 1 R1
id: valvola1_R1
restore_mode: ALWAYS_OFF
on_turn_on:
then:
- switch.turn_on: pompa_trasf
on_turn_off:
then:
- switch.turn_off: pompa_trasf
- platform: template
name: Pompa + Trasf. 24VAC
id: pompa_trasf
turn_on_action:
- then:
- switch.turn_on: pompa_R3
- switch.turn_on: trasf_R4
- switch.template.publish:
id: pompa_trasf
state: ON
turn_off_action:
- then:
- switch.turn_off: pompa_R3
- switch.turn_off: trasf_R4
- switch.template.publish:
id: pompa_trasf
state: OFF
with the switch pompa_trasf i’m turning on my pump and my transformer 220vac->24vac that powers electrovalves and the relay that control the 3phase water pump.
Hello I have intention use a shelly 1pm. Thanks
ok you control your pump with shelly 1 pm, and your valves?
Do you use tasmota or esphome? have you flashed the shelly or do you use it as is?
6 valves with tasmota.