Hi There -
Looking for some configuration help for the following automation:
I have a Vizio Smartcast TV and a Z-Wave Switch. I would like to create an automation that when the TV turns on, I would like to turn on the Z-Wave switch as well. Alternatively, when the TV turns off, I would like to turn off the Z-Wave switch as well.
Here’s where it gets tricky for me… I’ll describe the scenario below and share snippets of my configuration.
- I have a Vizio SmartCast TV configured on HA (verified that I can turn the TV on/off via the HA web interface)
- I have HA-Smartthings successfully integrated via MQTT Broker & Bridge
- Within HA, I have a “Smartthings” Z-Wave switch sucessfully configured (verified that I can turn the switch on/off via the HA web interface)
Here is my configuration for these items (snippets):
media_player family_room_tv:
- platform: vizio
host: 192.168.1.132
access_token: <hidden from post>
supress_warning: true
mqtt:
broker: localhost
protocol: 3.1
keepalive: 60
client_id: hass-1
username: <hidden from post>
password: <hidden from post>
switch bias_lights:
platform: mqtt
name: "Bias Lights"
state_topic: "smartthings/Bias Lights/switch"
command_topic: "smartthings/Bias Lights/switch"
payload_on: "on"
payload_off: "off"
retain: true
Now onto the automation part which is driving me batty… Can someone take a look at this and let me know what is wrong with this automation?
- alias: Bias Lights Off
trigger:
platform: state
entity_id: media_player.family_room_tv
to: 'off'
action:
- service: mqtt.publish
data:
topic: "smartthings/Bias Lights/switch"
payload: "off"
Thanks in advance!
If you have it in the switches.yaml file and can control via the HA interface (as you said above you can), then you’ll want to just use the “switch.turn_off” service instead of trying to send an MQTT Payload. Let HA handle that part.
- alias: Turn Soundbar Off with TV
trigger:
- entity_id: media_player.vizio_smartcast
from: 'on'
platform: state
to: 'off'
condition: []
action:
- data:
entity_id: switch.soundbar_power
service: switch.turn_off
This should get you going.
Thanks for the tip. I tried what you suggested, and it still is not working…
I’m using mosquitto_sub to subscribe to the MQTT broker to determine whether anything is being sent across the MQTT interface. It turns out I’m not seeing any message firing if I turn on or off the TV.
However, when I manually try to turn on/off the switch via smartthings or HA, I can see the message firing.
Client mosqsub|3106-ubuntu-ser received PUBLISH (d0, q0, r0, m0, 'smartthings/Bias Lights/switch', ... (3 bytes))
off
Is there a way I can verify that the state is changing correctly (even though I can turn on/off the TV thru HA)? I wonder if the trigger is not firing?
Here are my automations now:
- alias: Turn Bias Lights Off with TV
trigger:
- entity_id: media_player.family_room_tv
from: 'on'
platform: state
to: 'off'
condition: []
action:
- data:
entity_id: switch.bias_lights
service: switch.turn_off
- alias: Turn Bias Lights On with TV
trigger:
- entity_id: media_player.family_room_tv
from: 'off'
platform: state
to: 'on'
condition: []
action:
- data:
entity_id: switch.bias_lights
service: switch.turn_on
Some additional information which may help…
I wanted to validate whether the automation trigger was being fired, so I adjusted the automation to set a persistent message.
It turns out after I turn off the TV, there is no message being on the web UI. This leads me to believe that I have something wrong with how the trigger is set up to fire based off of a state change of the TV.
- alias: Turn Bias Lights Off with TV
trigger:
- entity_id: media_player.family_room_tv
from: 'on'
platform: state
to: 'off'
condition: []
action:
service: persistent_notification.create
data:
message: "TV Turned Off"
Again, any help would be much appreciated!
Thanks…
Sounds like the Automation itself isn’t running. You can attempt to manually run it from the services page. https://your.ha.instance:8123/dev-service and then select “automation.trigger” along with your Automation.
Thanks… I manually ran the “Turn Bias Lights Off with TV” automation trigger thru the services page, and the action fired (in this case the creation of a persistent notification), so something is definitely not right with the trigger.
Here is my full configuration.yaml can you let me know whether you see anything suspect?
homeassistant:
# Name of the location where Home Assistant is running
name: Home
# Location required to calculate the time the sun rises and sets
latitude: <hidden>
longitude: <hidden>
# Impacts weather/sunrise data (altitude above sea level in meters)
elevation: 229
# 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/Chicago
# Customization file
customize: !include customize.yaml
# Show links to resources in log and frontend
introduction:
# Enables the frontend
frontend:
# 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: yr
# Text to speech
tts:
- platform: google
# Cloud
cloud:
remote harmony_hub:
- platform: harmony
name: Harmony Hub
host: 192.168.1.101
activity: Watch TV
media_player family_room_channels:
- platform: channels
name: Family Room Channels
host: 192.168.1.133
media_player family_room_tv:
- platform: vizio
host: 192.168.1.132
access_token: <Hidden>
supress_warning: true
mqtt:
broker: localhost
protocol: 3.1
keepalive: 60
client_id: hass-1
username: <hidden>
password: <hidden>
switch bias_lights:
platform: mqtt
state_topic: "smartthings/Bias Lights/switch"
command_topic: "smartthings/Bias Lights/switch"
payload_on: "on"
payload_off: "off"
retain: true
group: !include groups.yaml
# automation: !include automations.yaml
script: !include scripts.yaml
automation:
- alias: Stop Channels
trigger:
- platform: state
entity_id: remote.harmony_hub
to: 'off'
action:
- service: media_player.media_stop
data:
entity_id: media_player.family_room_channels
- alias: Turn Bias Lights Off with TV
trigger:
- platform: state
entity_id: switch.bias_lights
to: 'off'
action:
- service: persistent_notification.create
data:
message: "TV Turned Off"
- alias: Turn Bias Lights On with TV
trigger:
- entity_id: media_player.family_room_tv
from: 'off'
platform: state
to: 'on'
action:
- service: switch.turn_on
entity_id: switch.bias_lights
Right off the bat
media_player family_room_tv
Looks wrong. There should be a “.” inbetween the media_player and family_room_tv.
The second part, at least how I have it setup, I don’t use that format for getting devices in.
I pull the devices in and then either change the Entity IDs in the entity_registry.yaml file.
Are you able to control the “Family Room TV” from HA? Is it updating when you turn it off and on from the remote?
When you say there should be a “.” in between. do you mean listing it as “media_player.family_room_tv” ?
To answer your second question. Yes, I am able to control the Family Room TV from HA, and am able to turn it on/off from the HA web interface. Additionally, the TV does report on/off in the HA web interface when I turn it on/off from via the remote.
This is what has been boggling me. It seems as if the automation trigger does not pick up the Vizio TV state change.
Any other debugging suggestions?
I’m really stumped by this…
Solved it…
I had the Vizio TV Device set up incorrectly.
I had this in my configuration.yaml
media_player family_room_tv:
- platform: vizio
host: 192.168.1.132
access_token: <Hidden>
supress_warning: true
When I should have included the “name” directive as well:
media_player family_room_tv:
- platform: vizio
name: "Family Room TV" <-- This was the missing piece
host: 192.168.1.132
access_token: <Hidden>
supress_warning: true
How I found out this was the problem was because when I looked in the logs, I saw the the device was named: media_player.vizio_smartcast, and it wasn’t only until after I added in the “name” directive that the device was actually called media_player.family_room_tv
I wasn’t aware of the dependency between the name: directive and unique identifier of the device.
Nonetheless, I FINALLY was able to get this working.
Marking thread as SOLVED!