Hello guys,
I’m pretty new to HA but I’m really interested in getting the best out of it.
I stucked on a think I find really ugly about scripting, at least because I didn’t find a proper solution to it yet. Is it really not possible to make this look better or get rid of some if’s there?
That is what I want to achieve. I think it’s much more readable like that and avoids repetition
shield_up:
sequence:
- service_template: >
{% if is_state('input_select.remote_sender', 'ADB') %}
androidtv.adb_command
{% elif is_state('input_select.remote_sender', 'Harmony') %}
remote.send_command
{% endif %}
data_template: >
{% if is_state('input_select.remote_sender', 'ADB') %}
entity_id: media_player.shield
command: UP
{% elif is_state('input_select.remote_sender', 'Harmony') %}
entity_id: remote.harmony_hub
device: 59035175
command: DirectionUp
{% endif %}
But I seem to have to do it like this because I read jinja2 or ha or whatever is the reason won’t take more than one line here
shield_up:
sequence:
- service_template: >
{% if is_state('input_select.remote_sender', 'ADB') %}
androidtv.adb_command
{% elif is_state('input_select.remote_sender', 'Harmony') %}
remote.send_command
{% endif %}
data_template: >
entity_id: >
{% if is_state('input_select.remote_sender', 'ADB') %}
media_player.shield
{% elif is_state('input_select.remote_sender', 'Harmony') %}
remote.harmony_hub
command: >
{% if is_state('input_select.remote_sender', 'ADB') %}
UP
{% elif is_state('input_select.remote_sender', 'Harmony') %}
DirectionUp
{% elif is_state('input_select.remote_sender', 'Harmony') %}
and even there you can see my problem because I don’t know what happens if I send the device data via adb to a device which doesn’t need it.
Can you tell me if there’s a better way to handle s.th. like this?
My Purpose is to have a remote for my shield but if harmony or adb for whatever reason is down (btw I prefer Harmony, lots faster) I want to be able to change inputs and use the other one instead.
Btw I tried a lot of things, read jinj2 and tried | instead of > to preserve spaces and even tried to get it to
work in the lovelace card which doesn’t seem to accepts templates, so I tried custom templates which lead to the same result + I don’t like logic in my ui cards
Thanks in advance Hope I can give this community some things back when I learned everything about HA:D
EDIT: I tried it the second way and it is how I assumed…
If I send the entry device to adb it doesn’t work and without harmony doesn’t work so still no good solution