I am interested in being able to change my TV channel using my google home. I am currently achieving this by using IFTT to trigger a script for each channel verbal command. This has quickly become tedious as I have to make a separate applet on IFTT and a corresponding script in HASS. Instead I am trying to come up with a way to pass a text ingredient from IFTT to HASS so I only need one script to parse all channels. To do this I have setup a custom sensor component for which I use the state to store the channel. Here is the code for my sensor which is in the file /custom_components/sensor/tvchannel.py:
from homeassistant.helpers.entity import Entity
def setup_platform(hass, config, add_devices, discovery_info=None):
add_devices([TvChannelSensor()])
class TvChannelSensor(Entity):
def __init__(self, name="TV Channel", state="0"):
self._name = name
self._state = state
@property
def name(self):
return self._name
@property
def state(self):
return self._state
Then I can simply use HTTP POST commands from IFTT to change the state of the sensor using the following:
https://hostname.duckdns.org:8123/api/states/sensor.tv_channel?api_password=<password>
with json data:
{ "state" : "{{TextField}}" , "attributes" : { "friendly_name" : "TV Channel" } }
This is actually working great to change the state, however it then reverts back to the previous state after around 10 seconds. Does anyone know why the state isn’t sticking?