action:
- service_template: frontend.set_theme
data_template:
name: >
{% if states.sun.sun.state == "above_horizon" %}
default
{% else %}
darkred
{% endif %}
- delay: 00:00:05
- service: notify.notify
data_template:
message: >-
It is {{ as_timestamp(now()) | timestamp_custom("%X") }},
Sun is {{states.sun.sun.state}} and Frontend is set to
{% if states.sun.sun.state == "above_horizon" %}default
{% else %}darkred
{% endif %}
Id rather use a template for the set Theme (I now have the same if then else construction, which is silly), but don’t know the correct syntax for that. Something like this maybe?
{{ action.service_data_state.attributes.name}}.
A bit like the {{trigger.to_state.attributes.friendly_name}}
Not sure if this is possible at all, but would be very nice.Please have a look?
ha, thats another interesting solution to remember indeed, thanks.
Not for this specific situation though, id like to template the theme name, not hard code it, as you still do now, albeit in the template sensor.
Seconde reason i asked, is id like to learn all about the tempting options, and lik there is some info on the trigger bit of the automations Automation trigger variables - Home Assistant, there is not a lot about actions.
id like to know whether, like with say trigger.to_state.attributes.friendly_name , a construction can be made with the condition, or action part of the automation so i can have a final data_template : message: theme set is {{theme_set}}.
I don’t think it is possible using frontend.set_theme (which needs a theme name to load the theme) so it should be done using the chosen option in the data_template.
Only other way i could think of now is set the themes per input_select, and use the {{states.input_select.set_day_theme.attributes.friendly_name}} and {{states.input_select.set_night_theme.attributes.friendly_name}} as template…
action:
- service_template: frontend.set_theme
data_template:
name: >
{% if states.sun.sun.state == "above_horizon" %}
{{states.input_select.set_day_theme.state}}
{% else %}
{{states.input_select.set_night_theme.state}}
{% endif %}
- delay: 00:00:05
- service: notify.notify
data_template:
message: >-
It is {{ as_timestamp(now()) | timestamp_custom("%X") }},
Sun is {{states.sun.sun.state}} and Frontend is set to
{% if states.sun.sun.state == "above_horizon" %}{{states.input_select.set_day_theme.attributes.friendly_name}}
{% else %}{{states.input_select.set_night_theme.attributes.friendly_name}}
{% endif %}
But, then again, i would be using the same template twice, while im looking for a possibility to use the action bit for a template in the service message.
But using a template sensor won’t hard code it. The sensor itself is variable, based on the time of day. Yes it would be hard coded in the template sensor, but you can change that by adjusting the template sensor to pull whatever info you want. The template sensor simply holds the data for you to easily use.
If you want to pull from your input selects, just adjust that in the template sensor:
action:
- service_template: frontend.set_theme
data_template:
name: {{ states.sensor.time_based_theme }}
- delay: 00:00:05
- service: notify.notify
data_template:
message: >-
It is {{ as_timestamp(now()) | timestamp_custom("%X") }},
Sun is {{states.sun.sun.state}} and Frontend is set to
{{ states.sensor.time_based_theme }}
getting more compact indeed.
Still, my quest for way to use the various parts in the automation remains. Would you know which is called what?
working nicely (added the 2 input_selects to the triggers of the automation for testing purposes only. Without the sun.sun.state to triggers, the automation kept being triggered to my surprise, since i would have thought it only to change state at sunset or rise…:
sensor:
- platform: template
sensors:
sun_based_theme:
friendly_name: Sun based theme
value_template: >
{% if is_state('sun.sun','above_horizon') %}
{{states.input_select.set_above_theme.state}}
{% else %}
{{states.input_select.set_below_theme.state}}
{% endif %}
icon_template: >
{% if is_state('sun.sun', 'above_horizon') %}
mdi:weather-sunny
{% else %}
mdi:weather-night
{% endif %}
input_select:
set_below_theme:
name: 'Select Below theme'
icon: mdi:weather-night
options:
- 'default'
- 'darkblue'
- 'darkcyan'
- 'darkorange'
- 'darkred'
- 'done'
- 'matrix'
- 'midnight'
- 'minimal'
- 'PmxMononight'
- 'stormy_hues'
- 'teal'
- 'vintage'
initial: 'darkred'
set_above_theme:
name: 'Select Above Theme'
icon: mdi:weather-sunny
options:
- 'default'
- 'darkblue'
- 'darkcyan'
- 'darkorange'
- 'darkred'
- 'done'
- 'matrix'
- 'midnight'
- 'minimal'
- 'PmxMononight'
- 'stormy_hues'
- 'teal'
- 'vintage'
initial: 'minimal'
automation:
- alias: Sun based theme change
id: '1511601488030'
initial_state: 'on'
trigger:
- platform: homeassistant
event: start
- platform: state
entity_id: sun.sun
to: above_horizon
- platform: state
entity_id: sun.sun
to: below_horizon
- platform: state
entity_id: input_select.set_below_theme
- platform: state
entity_id: input_select.set_above_theme
condition: []
action:
- service_template: frontend.set_theme
data_template:
name: >
{{ states.sensor.sun_based_theme.state }}
- delay: 00:00:05
- service: notify.notify
data_template:
message: >-
It is {{ as_timestamp(now()) | timestamp_custom("%X") }},
Sun is {{states.sun.sun.state}} and Frontend is set to
'{{ states.sensor.sun_based_theme.state }}'
Hi, can you tell me where i can find those themes? They are available for all or were created by you? In this case can you share them? I am newbie so i want to learn how to create themes…
I already read those docs… i am asking you to share as i think viewing directly i will learn more and faster… So if you want i’ll be glad to see and eventually use some of your themes.