You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Current way of creating configurations supports templates which is great but sometimes it becomes quite hard to maintain changes to objects belonging to the same functionality or entity in Home Assistant. The same entity_id is referenced uniquely a lot of times.
For example in the thermostat/climate example climate.thermostat_1 is referenced 52 times.
In media player examplemedia_player.sound_my_room is referenced 61 times.
This is even more true for pXbY object references, where all objects are on the same page. X could be a variable which could be specified at the beginning, and changing objects page can be done in a single place (likewise in the jsonl file, where page can be specified only once for the following objects).
It would be good to be able to use this for any repetitive part of the configuration, not just entity ids or page numbers.
Would make it easier to share code and multiply it to pages/plates simply by having to adjust only once the variables at the beginning.
Describe the solution you'd like
In the plate configuration, under the plate identifier slug (same level with objects) have a dictionary with user-defined variables which could be referenced in the configuration.
When parsing the configuration, resolve the variables back to their values before applying the template engine of HA. I think a programatic search and replace (regex?) would be enough.
Config should be possible something like:
openhasp:
plate35:
variables:
- climate_thermostat_1: "climate.thermostat_room_1" # assign to variable climate_thermostat_1 the name of entity in HA
- _page_thermostat_: 6
- media_player_1: "media_player.sound_my_room"
- media_player_sources: '["TV","Jazzy","Rádió 1","Retró","Sláger","Best FM","Forrás","Jzy Soul","Info"]'
- _page_media_player_: 3
objects: # resolve the variables within the templates
- obj: "p_page_thermostat_b41" # on/off switch
properties:
"val": "{{ 0 if (is_state('climate_thermostat_1', 'off') or is_state('climate_thermostat_1', 'unavailable')) else 1 }}"
event:
"down":
- service_template: >
{% if val == 0 -%}
climate.turn_on
{% else -%}
climate.turn_off
{% endif -%}
entity_id: "climate_thermostat_1"
- obj: "p_page_media_player_b2" # artist
properties:
"text": "{{ state_attr('media_player_1','media_artist') if state_attr('media_player_1','media_artist') else '-' }}"
- obj: "p_page_media_player_b40" # sources buttons
properties:
"options": media_player_sources
"toggle": '{{ 1 if ( not state_attr("media_player_1","source") in media_player_sources) or (is_state("media_player_1","unavailable")) -}}'
"val": >
{% if not (is_state('media_player_1','unavailable')) -%}
{% if not state_attr(media_player_1','source') in media_player_sources -%}-1{% else -%}
{% for source in media_player_sources -%}
{{loop.index - 1 if source == state_attr('media_player_1','source') }}
{%-endfor%}
{%- endif %}
{%- endif %}
Describe alternatives you've considered
Currently the users have to search and replace all occurences in the config, when applying the examples to their plates, or when duplicating/moving code from one plate/page to another.
Additional context
N/A
The text was updated successfully, but these errors were encountered:
This upgrades the current "list of services" restriction to allow the full syntax of HA scripts.
fixesHASwitchPlate#65
As a side-effect this also requires to generate a context for the script to run.
see HASwitchPlate#96
This can also be seen as a preparatory step to allow defining HASPObject-wide variables.
see HASwitchPlate#63
This upgrades the current "list of services" restriction to allow the full syntax of HA scripts.
fixesHASwitchPlate#65
As a side-effect this also requires to generate a context for the script to run.
see HASwitchPlate#96
This can also be seen as a preparatory step to allow defining HASPObject-wide variables.
see HASwitchPlate#63
Is your feature request related to a problem? Please describe.
Current way of creating configurations supports templates which is great but sometimes it becomes quite hard to maintain changes to objects belonging to the same functionality or entity in Home Assistant. The same
entity_id
is referenced uniquely a lot of times.For example in the thermostat/climate example
climate.thermostat_1
is referenced 52 times.In media player example
media_player.sound_my_room
is referenced 61 times.This is even more true for
pXbY
object references, where all objects are on the same page.X
could be a variable which could be specified at the beginning, and changing objects page can be done in a single place (likewise in the jsonl file, where page can be specified only once for the following objects).It would be good to be able to use this for any repetitive part of the configuration, not just entity ids or page numbers.
Would make it easier to share code and multiply it to pages/plates simply by having to adjust only once the variables at the beginning.
Describe the solution you'd like
In the plate configuration, under the plate identifier slug (same level with
objects
) have a dictionary with user-defined variables which could be referenced in the configuration.When parsing the configuration, resolve the variables back to their values before applying the template engine of HA. I think a programatic search and replace (regex?) would be enough.
Config should be possible something like:
Describe alternatives you've considered
Currently the users have to search and replace all occurences in the config, when applying the examples to their plates, or when duplicating/moving code from one plate/page to another.
Additional context
N/A
The text was updated successfully, but these errors were encountered: