install without package
emilianogetino opened this issue · 3 comments
hello,
hello,
Everything is working fine for me, but I don't use packages, I have set in my config.yaml:
`template:
- sensor:
- name: "Unavailable Entities"
unique_id: 7910ec5c-c7ae-4346-a8b9-42d85cc9c92f
icon: "{{ iif(states(this.entity_id)|int(-1) > 0,'mdi:alert-circle','mdi:check-circle') }}"
state_class: measurement
unit_of_measurement: entities
state: >`
I would like to remove this from my config.yaml and put it in a file inside my "sensors" directory.
To do this, I include a file called unavailable,yalm in my sensors directory with the following content:
`platform: template
sensors:
entities_unavailable:
unique_id: 7910ec5c-c7ae-4346-a8b9-42d85c77c92f
icon: "{{ iif(states(this.entity_id)|int(-1) > 0,'mdi:alert-circle','mdi:check-circle') }}"
state_class: measurement
unit_of_measurement: entities
state: >
{% set entities = state_attr(this.entity_id,'entity_id') %}
{{ entities|count if entities != none else none }}
attributes:
entity_id: >
{% set ignore_seconds = 60 %}
{% set ignored = state_attr('group.ignored_unavailable_entities','entity_id') %}
{% set ignore_ts = (now().timestamp() - ignore_seconds)|as_datetime %}
{% set entities = states
|rejectattr('domain','in',['button','event','group','input_button','input_text','scene'])
|rejectattr('entity_id','in',integration_entities('Browser Mod'))
|rejectattr('entity_id','search','(this_device|dlna_|_repeat_switch|_shuffle_switch|_next_alarm|_next_reminder|_next_timer)')
|rejectattr('last_changed','ge',ignore_ts) %}
{% set entities = entities|rejectattr('entity_id','in',ignored) if ignored != none else entities %}
{{ entities|map(attribute='entity_id')|reject('has_value')|list|sort }} `
This gives me errors and I can't get it to work, I have all my other sensors configured like this without problems, but this one is driving me crazy.
¡Configuración no válida!
Invalid config for [sensor.template]: [icon] is an invalid option for [sensor.template]. Check: sensor.template->sensors-
entities_unavailable->icon. (See ?, line ?).
if I remove the icon:
Invalid config for [sensor.template]: [state_class] is an invalid option for [sensor.template]. Check: sensor.template->sensors->entities_unavailable->state_class. (See ?, line ?).
if I remove the device_class:
Invalid config for [sensor.template]: [state] is an invalid option for [sensor.template]. Check: sensor.template->sensors->entities_unavailable->state. (See ?, line ?).
any ideas?
thank you.
-
You have not copied and pasted the code into your comment here correctly, and it was not formatted as code so it is VERY difficult for someone else to read. I have tried to reformat it for you.
-
You are trying to change the template to a very old style template format which is no longer recommended. Just a heads up, eventually that method may not even be supported in the future.
-
You cannot directly transfer the modern preferred method of declaring templates to the old style. They parameters have different names and some parameters are not valid at all. The parameters that are accepted in the old style template are listed here. If they are not listed (eg icon, state_class) they are not valid. Make sure you rename parameters that require it and remove any that are not listed.
My recommendation is to use the new method of declaring your templates to avoid these issues.
Thank you very much for your comments, and as you say, the best thing would be to leave this sensor as it is and start migrating the rest of the sensors to the new format, the longer you wait, the more you will have to change, haha.
As for inserting code, if you tell me how to do it correctly I would appreciate it, so next time I will do it right.
What I did was click on insert code above (ctrl+e), two quotes came out and between the quotes I pasted my code, thinking it was the correct way, but I see that it wasn't.
All the best.
Select the code you wish to highlight as code and click the Code button in the toolbar.
{% set ignore_seconds = 60 %}
{% set ignored = state_attr('group.ignored_unavailable_entities','entity_id') %}
{% set ignore_ts = (now().timestamp() - ignore_seconds)|as_datetime %}
{% set entities = states
|rejectattr('domain','in',['button','event','group','input_button','input_text','scene'])
|rejectattr('entity_id','in',integration_entities('Browser Mod'))
|rejectattr('entity_id','search','(this_device|dlna_|_repeat_switch|_shuffle_switch|_next_alarm|_next_reminder|_next_timer)')
|rejectattr('last_changed','ge',ignore_ts) %}
{% set entities = entities|rejectattr('entity_id','in',ignored) if ignored != none else entities %}
{{ entities|map(attribute='entity_id')|reject('has_value')|list|sort }}