Hi all,
I’m new to Home Assistant, and have been working on setting it up for my home over the last month. Overall it’s gone smoothly, and it’s been really impressive how easy it is to implement everything. But I hit a snag recently working on an automation around the Logitech Harmony Hub component, and I wanted to share it in case it’s a legitimate bug, or to help others who may encounter the same issue.
Context
In my bedroom I have a lamp with a Philips Hue bulb, plus a Harmony Hub remote for the TV. I wanted to set up a sleep timer so that I could watch TV while falling asleep, and after a specified amount of time, the TV and lamp would both turn off. I attempted to accomplish this by using the Timer component, a switch, and an automation:
Timer
timer:
bedroom_sleep:
name: Bedroom Sleep Timer
icon: mdi:sleep
Sample Switch
# Note that timers can have custom durations, so it's possible to have
# multiple switches with different duration values
switch:
platform: template
switches:
bedroom_sleep_30_minutes:
friendly_name: 'Bedroom Sleep 30 Minutes'
icon_template: mdi:sleep
value_template: "{{
is_state('timer.bedroom_sleep', 'active') and
states.timer.bedroom_sleep.attributes.duration == '0:30:00' }}"
turn_on:
service: timer.start
data:
entity_id: timer.bedroom_sleep
duration: '00:30:00'
turn_off:
service: timer.cancel
data:
entity_id: timer.bedroom_sleep
Automation
automation:
- alias: 'Bedroom TV Sleep Timer'
id: bedroom_tv_sleep_timer
trigger:
platform: event
event_type: timer.finished
event_data:
entity_id: timer.bedroom_sleep
action:
# note the use of the 'data' key for all 3 elements here; this is how I
# originally wrote it. Spoiler alert: this turned out to be the problem
- service: remote.turn_off
data:
entity_id: remote.bedroom_harmony
- service: light.turn_off
data:
entity_id: light.bedroom_lamp
- service: notify.ios_my_device
data:
title: 'Sleep Timer Finished'
message: 'Goodinght!'
Problem & Solution
When I first added the configuration above, the timer and switch worked as expected, but the automation never fired. Through troubleshooting I learned that the notification and light actions worked fine, but the Harmony remote action did not. Additionally, if the Harmony remote action was first in the list, then subsequent actions wouldn’t fire, and the Home Assistant log contained no clues as to why.
Update: I thought I had figured out the solution, but the problem persists in subsequent testing. I’m striking out the original hypothesis but preserving the text for continuity’s sake. Thanks to @pnbruckner for providing evidence to debunk it below.
Update 2: The problem was that the automation was somehow turned off. Once I turned it back on, everything worked as expected. Thanks again to @pnbruckner for the troubleshooting help.
After racking my brain for a while, and searching the forums for similar issues, I realized that the problem was rooted in a quirk of syntax. In the “action:
” section of the automation, the service call for the Harmony remote needs to look like this:
- service: remote.turn_off
entity_id: remote.bedroom_harmony
Note the lack of a “data:
” key above “entity_id
”. If written as it is here, the service call succeeds and everything works fine. But if written as I originally wrote it above, there’s no indication of a syntax error, and the service call fails silently, taking the automation down with it.
Indeed, the Harmony Hub Remote documentation contains an example that shows the correct syntax, and I had overlooked that when I first wrote this. Still, the lack of consistency in the syntax strikes me as a bug. I would expect the action syntax for Harmony remote service calls to work if written the same as the others (i.e. with the data
key) as in my original example above. Barring that, the incorrect syntax should at least trigger an error or warning instead of failing silently.
Can anyone back me up on this? If so I’ll happily file and issue on GitHub. I’d just like to get a second opinion before cluttering the HA GitHub issues.
Thanks!