works perfect!
I’ve posted the wrong automation, The correct one is:
automation:
- alias: Automatic Theme Change
trigger:
- platform: homeassistant
event: start
condition:
condition: or
conditions:
- condition: sun
after: sunset
- condition: sun
before: sunrise
action:
- service_template: frontend.set_theme
data_template:
name: >
{% if states.sun.sun.state == "above_horizon" %}
default
{% else %}
darkred
{% endif %}
This will only trigger once and on HA start. There’s still no need for conditions in the automation as the condition can actually be a trigger. what I posted is what they are looking for. They want it to trigger on sunrise and sunset and load the theme accordingly.
Hi @squirtbrnr
using this and adding some feedback. Im struggling a bit though to have it display the set theme in the message with a template, cant find the frontend.theme states anywhere… Obviously i don’t want to hardcode the theme in the message but have it read the last set theme, form the automation. To give it time to do so i have added a 2 sec delay, after which it should be able to find the set theme through a template?
- alias: Automatic Theme Change
id: '1511601478030'
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
condition: []
action:
- service_template: frontend.set_theme
data_template:
name: >
{% if states.sun.sun.state == "above_horizon" %}
default
{% else %}
darkred
{% endif %}
- delay: 00:00:02
- service: notify.notify
data_template:
message: 'It is {{ as_timestamp(now()) | timestamp_custom("%X") }} and
Frontend is set to Darkred.'
hope to be able to do something like this:
data_template:
message: 'It is {{ as_timestamp(now()) | timestamp_custom("%X") }},
Sun is {{states.sun.sun.state}} and
Frontend is set to {{states.frontend.theme.friendly_name}}'
I don’t think frontend.theme
is a component that you can get the state from. I think you’ll have to hardcode it. There are only two services exposed for frontend and those are .set_theme
and .reload_themes
.
I tried using the template validator on the frontend for things like {{ states.frontend.get_theme }}
or {{ states.frontend.theme.friendly_name }}
and they either returned an error, nothing, or “None”.
yes i noticed that, seems a bit odd.
enable Frontend in the component section to be able to use it in templating, example:
data_template:
message: 'It is {{ as_timestamp(now()) | timestamp_custom("%X") }},
Sun is {{states.sun.sun.state}} and
Frontend is set to {{states.frontend.theme.friendly_name}}'
HI,
since Backend-selected is out of reach in the set theme configuration page on my computer (and iPhone btw) ( it won’t scroll up past default::
i tried to use this input_select:
input_select:
set_current_theme:
name: 'Set Current Theme'
options:
- 'Backend-selected'
- 'default'
- 'teal'
- 'darkorange'
- 'darkred'
- 'darkcyan'
- 'minimal'
- 'vintage'
initial: 'Backend-selected'
icon: 'mdi:palette'
automation:
- id: change_current_theme
alias: 'Change Current Theme'
initial_state: 'on'
trigger:
- platform: state
entity_id: input_select.set_current_theme
action:
- service: frontend.set_theme
data_template:
name: '{{states.input_select.set_current_theme.state}}'
It does work…
Maybe the automation is incorrect?
What is the name of the backend-selected theme to call in this input_select?
please have a look?
Marius
Is there possibility to change theme remotely on e.g. particular unit. E.g. device_tracker.device_ten
not that I am aware off. but you can set a theme for each device.
as far as I know you cant change the data of say your phone or tablet from home assistant remotely. because the selected theme is saved on your phone/tablet and not in home assistant.
My automations…
# /config/automations/
# auto_theme.yaml
- alias: Automaticka zmena Temy
initial_state: 'on'
trigger:
- platform: state
entity_id: sun.sun
action:
- service_template: frontend.set_theme
data_template:
name: >
{% if states.sun.sun.state == "above_horizon" %}
{{ "default" }}
{% else %}
{{ "midnight" }}
{% endif %}
hi all , after Home assistant update 0.113 , my theme automation based on the sun broke. can any help please.
alias: HA Theme based on day and night
trigger:
- event: start
platform: homeassistant - entity_id: sun.sun
platform: state
to: above_horizon - entity_id: sun.sun
platform: state
to: below_horizon
action: - data:
data_template:
name: “{% if states.sun.sun.state == “above_horizon” %}\n Light - Light
\ Red\n{% else %}\n Dark - Light Red\n{% endif %}\n”
service: frontend.set_theme
It’s broken here also, did you find a way to fix it?
what is broken? post your automation in correctly formatted yaml, and we can have a look.
In any case these are the correct sun triggers
Sadly no , HA screwed up the automation, Temporary i just made two Automation one for Day and One night.
we are talking about Theme change based on SUN trigger.
Yes. Sure.
Post the automation so we can help
in any case, use this:
trigger:
- platform: sun
event: sunrise
- platform: sun
event: sunset
Here
Note, that the below used to work perfectly before the update
event: start
platform: homeassistant
entity_id: sun.sun
platform: state
to: above_horizon
entity_id: sun.sun
platform: state
to: below_horizon
action:
data:
data_template:
name: “{% if states.sun.sun.state == “above_horizon” %}\n Light - Light
\ Red\n{% else %}\n Dark - Light Red\n{% endif %}\n”
service: frontend.set_theme
well, that seems hardly possible… there’s no single spacing in the full automation. you might want to have a look at what’s in the docs and what people post here.
I’ve given you the correct triggers already, in the correct format. Why don’t you start with that and build, using
service: frontend.set_theme
data:
name: >
{% if trigger.event == 'sunrise' %} Sunrise theme name
{% else %} Sunset theme name
{% endif %}
have a look here, for 2 automations to give you an idea how things work:
automation:
- alias: Change current theme
id: Change current theme
trigger:
platform: state
entity_id: input_select.theme
action:
service: frontend.set_theme
data:
name: >
{{states('input_select.theme')}}
- alias: Sun based theme change
id: Sun based theme change
trigger:
platform: state
entity_id: sensor.sun_based_theme
condition:
condition: numeric_state
entity_id: sensor.uptime_minutes
above: 1
action:
- service: input_select.select_option
data:
entity_id: input_select.theme
option: >
{{states('sensor.sun_based_theme')}}
- condition: state
entity_id: input_boolean.notify_system
state: 'on'
- service: notify.system
data:
title: >
Ha Rpi4: Sun based Theme
message: >
{{as_timestamp(now())|timestamp_custom('%X')}}:
Sun is {{states('sun.sun')}} and Frontend is set to '{{states('sensor.sun_based_theme')}}'
Hello,
any idea why this is unsuccessful ?
the theme is not set, nothing change. and no error in the logs
Also not working for me; not sure what is wrong or what changed?