Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching by days of the week + sunrise or sunset #47

Open
DivanX10 opened this issue Aug 19, 2021 · 1 comment
Open

Switching by days of the week + sunrise or sunset #47

DivanX10 opened this issue Aug 19, 2021 · 1 comment

Comments

@DivanX10
Copy link

I can configure switching video wallpapers by days of the week or sunrise or sunset. Tell me how to make it so that you can switch not only by days of the week but also by sunrise or sunset? The first example works on days of the week, and the second example does not work on days of the week + sunrise or sunset.

This option works on days of the week

animated_background:
  default_url: /local/animated-background/day/01.mp4
  included_users:
    - users_01
  entity: sensor.dayoftheweek
  state_url:
    Thursday:
      - /local/animated-background/day/Switzerland_01.mp4
      - /local/animated-background/night/04.mp4
      - /local/animated-background/night_space/Space_05.mp4
    Friday:
      - /local/animated-background/day/Switzerland_01.mp4
      - /local/animated-background/night/04.mp4

This option does not work on days of the week + sunrise or sunset

animated_background:
  default_url: /local/animated-background/day/01.mp4
  included_users:
    - users_01
  entity: sensor.dayoftheweek
  state_url:
    Thursday:
      above_horizon:
        - /local/animated-background/day/Switzerland_01.mp4
        - /local/animated-background/night/04.mp4
      below_horizon:
        - /local/animated-background/night_space/Space_05.mp4
    Friday:
      above_horizon:
        - /local/animated-background/day/Switzerland_01.mp4
        - /local/animated-background/night/04.mp4
      below_horizon:
        - /local/animated-background/night_space/Space_05.mp4
@DivanX10
Copy link
Author

DivanX10 commented Aug 20, 2021

I figured out how to implement what I wanted. I have created a sensor that shows the day of the week and the sunset or sunrise.

image

# Сенсор дня недели
sensor:
  - platform: template
    sensors:
      dayoftheweek:
        value_template: "{{ ['Monday','Tuesday','Wednesday', 'Thursday','Friday', 'Saturday', 'Sunday'][now().weekday()] }}"
        entity_id: sensor.time
        icon_template: mdi:calendar-month

# Day of the week and sun sensor
  - platform: template
    sensors:
      day_week_and_sun:
        friendly_name: "Day of the week and sun sensor"
        value_template: >
          {% set sunrise = is_state('sun.sun','above_horizon') %}
          {% set sunset = is_state('sun.sun','below_horizon') %}
          {% if sunrise %}
          {{ states.sensor.dayoftheweek.state }}. Sunrise
          {% elif sunset %}
          {{ states.sensor.dayoftheweek.state }}. Sunset
          {% endif %}
        icon_template: >-
          {% if is_state('sun.sun','above_horizon') %}
          mdi:sunrise
          {% elif is_state('sun.sun','below_horizon') %}
          mdi:sunset
          {% endif %}

And I made a wallpaper change not only by the days of the week, but also by sunset and sunrise

animated_background:
  default_url: /local/animated-background/day/01.mp4
  included_users:
    - users
  entity: sensor.day_week_and_sun
  state_url:
    Monday. Sunrise:
      - /local/animated-background/day/Switzerland_01.mp4
      - /local/animated-background/day/Switzerland_02.mp4
    Monday. Sunset:
      - /local/animated-background/night/Moon and lake.mp4
      - /local/animated-background/night/Mountain and lake.mp4
    Tuesday. Sunrise:
      - /local/animated-background/day/Switzerland_03.mp4
      - /local/animated-background/day/Switzerland_04.mp4
    Tuesday. Sunset:
      - /local/animated-background/night/03.mp4
      - /local/animated-background/night/04.mp4
    Wednesday. Sunrise:
      - /local/animated-background/day/Iceland_01.mp4
      - /local/animated-background/day/Iceland_02.mp4
    Wednesday. Sunset:
      - /local/animated-background/night/Space_01.mp4
      - /local/animated-background/night/Space_02.mp4
    Thursday. Sunrise:
      - /local/animated-background/day/Iceland_03.mp4
      - /local/animated-background/day/Iceland_04.mp4
    Thursday. Sunset:
      - /local/animated-background/night/Space_03.mp4
      - /local/animated-background/night/Space_04.mp4
    Friday. Sunrise:
      - /local/animated-background/day/Iceland_05.mp4
      - /local/animated-background/day/Iceland_06.mp4
    Friday. Sunset:
      - /local/animated-background/night/Space_05.mp4
      - /local/animated-background/night/Space_06.mp4
    Saturday. Sunrise:
      - /local/animated-background/day/Switzerland_05.mp4
      - /local/animated-background/day/Switzerland_06.mp4
    Saturday. Sunset:
      - /local/animated-background/night/Space_07.mp4
      - /local/animated-background/night/Space_08.mp4
    Sunday. Sunrise:
      - /local/animated-background/day/Switzerland_07.mp4
      - /local/animated-background/day/Switzerland_08.mp4
    Sunday. Sunset:
      - /local/animated-background/night/Space_03.mp4
      - /local/animated-background/night/Space_02.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant