Alternate between two input_select options every 5 minutes

If I’m understanding things correctly, this is the entity ID:

entity_id: input_select.holiday_led_effect

Options are:

Christmas,Candy Cane,Holly Jolly,Valentine,Lovey Day,St Patty,Easter,USA,Independence,Go Blue,Go Eagles,Hail,Touchdown,Halloween,Punkin,Thanksgiving,Turkey Day,BPM,Confetti,Cyclon Rainbow,Dots,Fire,Glitter,Juggle,Lightning,Police All,Police One,Rainbow,Rainbow with Glitter,Ripple,Sinelon,Solid,Snow Sparkle,Test,Twinkle,Warm Glow
friendly_name: Holiday LED Effect

In one of the other automations I created (via GUI), I used this command to send an option change:

{
“entity_id”: “input_select.holiday_led_effect”,
“option”: “Halloween”
}

Here are the entire contents of my config file and yes, that line does appear to exist:

homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: 35.3832
  longitude: -119.2272
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 0
  # metric for Metric, imperial for Imperial
  unit_system: imperial
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: America/Los_Angeles
  # Customization file
  customize: !include customize.yaml

# Show links to resources in log and frontend
#introduction:
      
      
# Enables the frontend
frontend:

### THIS IS ONLY A PARTIAL CONFIGURATION FILE. 
### JUST ADD THESE PARTS TO YOUR configuration.yaml
mqtt:
  broker: core-mosquitto
  username: drivium
  password: goonies

#######################################
############## Holiday Outside Lights ######
#######################################

light:
  - platform: mqtt
    name: "Holiday Lights"
    command_topic: "bruh/mqttstrip/setpower"
    state_topic: "bruh/mqttstrip/setpowerpub"
    rgb_state_topic: "bruh/mqttstrip/setcolorpub"
    rgb_command_topic: "bruh/mqttstrip/setcolor"
    brightness_state_topic: "bruh/mqttstrip/setbrightnesspub"
    brightness_command_topic: "bruh/mqttstrip/setbrightness"
    optimistic: false

input_select:
  holiday_led_effect:
    name: Holiday LED Effect
    options:
     - "Christmas"
     - "Candy Cane"
     - "Holly Jolly"
     - "Valentine"
     - "Lovey Day"
     - "St Patty"
     - "Easter"
     - "USA"
     - "Independence"
     - "Go Blue"
     - "Go Eagles"
     - "Hail"
     - "Touchdown"
     - "Halloween"
     - "Punkin"
     - "Thanksgiving"
     - "Turkey Day"
     - "BPM"
     - "Confetti"
     - "Cyclon Rainbow"
     - "Dots"
     - "Fire"
     - "Glitter"
     - "Juggle"
     - "Lightning"
     - "Police All"
     - "Police One"
     - "Rainbow"
     - "Rainbow with Glitter"
     - "Ripple"
     - "Sinelon"
     - "Solid"
     - "Snow Sparkle"
     - "Test"
     - "Twinkle"
     - "Warm Glow"
    initial: "Warm Glow"

input_number:
  animation_speed:
    name: Animation Speed
    initial: 150
    min: 1
    max: 150
    step: 10

automation old: 
  - alias: "Holiday Input Effect"
    initial_state: True
    hide_entity: False
    trigger:
      - platform: state
        entity_id: input_select.holiday_led_effect
    action:
      - service: mqtt.publish
        data_template:
          topic: "bruh/mqttstrip/seteffect"
          payload: '{{ trigger.to_state.state | string }}'

  - alias: "Animation Speed"
    initial_state: True
    hide_entity: False
    trigger:
      - platform: state
        entity_id: input_number.animation_speed
    action:
      - service: mqtt.publish
        data_template:
          topic: "bruh/mqttstrip/setanimationspeed"
          payload: '{{ trigger.to_state.state | int }}'


# Enables configuration UI
config:

http:
  # Secrets are defined in the file secrets.yaml
  # api_password: !secret http_password
  # Uncomment this if you are using SSL/TLS, running in Docker container, etc.
  # base_url: example.duckdns.org:8123

# Checks for available updates
# Note: This component will send some information about your system to
# the developers to assist with development of Home Assistant.
# For more information, please see:
# https://home-assistant.io/blog/2016/10/25/explaining-the-updater/
updater:
  # Optional, allows Home Assistant developers to focus on popular components.
  # include_used_components: true

# Discover some devices automatically
discovery:

# Allows you to issue voice commands from the frontend in enabled browsers
conversation:

# Enables support for tracking state changes over time
history:

# View all events in a logbook
logbook:

# Enables a map showing the location of tracked devices
map:

# Track the sun
sun:

# Weather prediction
sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'beat'



# Text to speech
tts:
  - platform: google

 
 
automation: !include automations.yaml
script: !include scripts.yaml
group: !include groups.yaml

I’ll add that I set this up a year ago following this tutorial: https://www.youtube.com/watch?v=6Y6jUM1OaYM

No worries, copy and paste this into your automations.yaml file and restart homeassistant.

Before you do, just have a quick look at your entities list and make sure that you have an entity called light.holiday_lights and it hasn’t called it something like light.mqtt_holiday_light or something. If it has you’ll need to update the entity_id line in 2 places.

The entities list is found by clicking the
<> icon in the dev panel on the sidebar. Just scroll down to the lights and it should be fairly obvious which one you need (hopefully I’ve already got it right)

#automations
  - alias: Holiday Lights Off At Midnight
    initial_state: on 
    trigger:
      at: '23:59:59'
      platform: time
    action:
      service: light.turn_off
      entity_id: light.holiday_lights

  - alias: Holiday Lights On At Sundown
    initial_state: on
    trigger:
      event: sunset
      offset: -00:45:10
      platform: sun
    action:
      service: input_select.select_option
      entity_id: input_select.holiday_led_effect
      option: Halloween 

  - alias: Swap led effects 
    initial_state: on 
    trigger:
      platform: time 
      seconds: '/5'
    condition:
      condition: state
      entity_id: light.holiday_lights
      state: 'on' 
    action:
      service: input_select.select_option
      data_template:
        entity_id: input_select.holiday_led_effect
        option: >
          {% if is_state('input_select.holiday_led_effect' , 'Halloween') %} Punkin
          {% else %} Halloween {% endif %}

LMK what happens when you restart :slight_smile:

Yep, I have

light.holiday_lights

Replaced automations contents with yours and rebooting…

Sitting here gormlessly staring at my phone with my fingers crossed…

1 Like

Same message about invalid config…

Not sure if it matters, but I’m using notepad++ for editing…

OK, click the little i in the circle and find the error message for “couldn’t set up automation” and paste it here for me.

Here is entire log…at first glance, I’m not seeing the message you mentioned:

2018-10-25 20:35:13 WARNING (Recorder) [homeassistant.components.recorder] Ended unfinished session (id=66 from 2018-10-26 03:02:41.354503)
2018-10-25 20:35:13 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: [option] is an invalid option for [automation]. Check: automation->action->0->option. (See /config/configuration.yaml, line 172). Please check the docs at https://home-assistant.io/components/automation/
2018-10-25 20:35:25 WARNING (SyncWorker_14) [netdisco.ssdp] Error fetching description at http://192.168.1.6:8200/rootDesc.xml
2018-10-25 20:35:32 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform plex
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 171, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 79, in create_connection
    raise err
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 69, in create_connection
    sock.connect(sa)
OSError: [Errno 113] Host is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 354, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 196, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 180, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x70813390>: Failed to establish a new connection: [Errno 113] Host is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 445, in send
    timeout=timeout
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='192.168.1.99', port=32400): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x70813390>: Failed to establish a new connection: [Errno 113] Host is unreachable',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 128, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/media_player/plex.py", line 94, in setup_platform
    hass, config, add_entities_callback
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/media_player/plex.py", line 113, in setup_plexserver
    token, cert_session
  File "/usr/local/lib/python3.6/site-packages/plexapi/server.py", line 102, in __init__
    data = self.query(self.key, timeout=timeout)
  File "/usr/local/lib/python3.6/site-packages/plexapi/server.py", line 341, in query
    response = method(url, headers=headers, timeout=timeout, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 525, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 512, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 622, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 513, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.1.99', port=32400): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x70813390>: Failed to establish a new connection: [Errno 113] Host is unreachable',))
2018-10-25 20:35:38 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_protocol.py", line 242, in data_received
    messages, upgraded, tail = self._request_parser.feed_data(data)
  File "aiohttp\_http_parser.pyx", line 523, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: invalid HTTP method
2018-10-25 20:36:05 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting

Thank you for your help with this… you didn’t have to…but here you are…doing it… Much appreciated!

Yep, got it, on the second automation, called Holiday lights on at sundown, change the action section from this…

action:
  service: input_select.select_option
  entity_id: input_select.holiday_led_effect
  option: Halloween

To

action:
  service: input_select.select_option
  data:
    entity_id: input_select.holiday_led_effect
    option: Halloween

(preserving the indentation with spaces, so the D of Data is under the S of Service, and the lower two lines are 2 spaces farther in)

Ha, you’re welcome :+1:

Edited and rebooting.

I’ve been resetting HA by just pulling power plug to Pi… Is there another way I should be restarting HA?

Yeah, don’t pull the plug, you can very easily corrupt your installation :slight_smile:

Hassio or venv or docker install? Or something else entirely?

Hassio

Ok, just realized I missed the detail about “d below the s” and it wasn’t the case… Fixed and rebooting… Finicky as Python! lol

Same invalid config message… Also received a message from these forums that I’ve reached the max number of replies for a new user (22)… So, I may just have to edit this one if we keep going…

I don’t use hassio, so this might not be accurate, but from the quickest of searches the correct way to reboot should hopefully be…

Hassio > System > Reboot

Ok. Thank you.

Newest log loading…

Maybe you could upload the fixed automations file somewhere and I can use your version? It’s possible I’m doing something wrong with the indents, spaces, etc.

2018-10-25 20:54:48 WARNING (Recorder) [homeassistant.components.recorder] Ended unfinished session (id=68 from 2018-10-26 03:51:05.795216)
2018-10-25 20:54:49 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: [service] is an invalid option for [automation]. Check: automation->service. (See /config/configuration.yaml, line 172). Please check the docs at https://home-assistant.io/components/automation/
2018-10-25 20:55:01 WARNING (SyncWorker_14) [netdisco.ssdp] Error fetching description at http://192.168.1.6:8200/rootDesc.xml
2018-10-25 20:55:07 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting
2018-10-25 20:55:11 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform plex
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 171, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 79, in create_connection
    raise err
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 69, in create_connection
    sock.connect(sa)
OSError: [Errno 113] Host is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 354, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 196, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 180, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x706adf90>: Failed to establish a new connection: [Errno 113] Host is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 445, in send
    timeout=timeout
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='192.168.1.99', port=32400): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x706adf90>: Failed to establish a new connection: [Errno 113] Host is unreachable',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 128, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/media_player/plex.py", line 94, in setup_platform
    hass, config, add_entities_callback
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/media_player/plex.py", line 113, in setup_plexserver
    token, cert_session
  File "/usr/local/lib/python3.6/site-packages/plexapi/server.py", line 102, in __init__
    data = self.query(self.key, timeout=timeout)
  File "/usr/local/lib/python3.6/site-packages/plexapi/server.py", line 341, in query
    response = method(url, headers=headers, timeout=timeout, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 525, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 512, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 622, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 513, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.1.99', port=32400): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x706adf90>: Failed to establish a new connection: [Errno 113] Host is unreachable',))

Update! Success! I tried editing the file in standard notepad and fixed a couple of (seemingly) small things, rebooted and it’s now working!

Earlier you said

If I knew what the entity_id was, I would use that entity being ‘on’ as a condition for the Swap-led-effects one, which I suspect is how you want it to behave.

I’m not sure I’m following this…

Ah, yes, I get it. That’s easy enough to set up. Ok, I won’t take any more of your time. Thank you VERY much for all of your patience and help. I’ve learned a lot here.

1 Like

I don’t use hassio, so this might not be accurate, but from the quickest of searches the correct way to reboot should hopefully be…

Hassio > System > Reboot

Ugh, that’s crap.

Can you paste the error log somewhere again?

OK, here in a box…

#automations
  - alias: Holiday Lights Off At Midnight
    initial_state: on 
    trigger:
      at: '23:59:59'
      platform: time
    action:
      service: light.turn_off
      entity_id: light.holiday_lights

  - alias: Holiday Lights On At Sundown
    initial_state: on
    trigger:
      event: sunset
      offset: -00:45:10
      platform: sun
    action:
      service: input_select.select_option
      data:
        entity_id: input_select.holiday_led_effect
        option: Halloween 

  - alias: Swap led effects 
    initial_state: on 
    trigger:
      platform: time 
      seconds: '/5'
    condition:
      condition: state
      entity_id: light.holiday_lights
      state: 'on' 
    action:
      service: input_select.select_option
      data_template:
        entity_id: input_select.holiday_led_effect
        option: >
          {% if is_state('input_select.holiday_led_effect' , 'Halloween') %} Punkin
          {% else %} Halloween {% endif %}

And here in a gist…

Awesome :slight_smile:

LMK how you get on when you can post again :laughing:

So, the automation will trigger every 5 minutes to toggle the input_select, but only when the light is on.

So if you turn that light on now, at some point in the next 5 minutes the input_select will change and the led effects will change, then 5 minutes later the same again, and every 5 minutes until either you switch the light off, or the automation does it for you at midnight.

Then they’ll go on again at sundown, and toggle every 5 minutes etc.

My pleasure :+1:

1 Like