Repository navigation
Home Assistant over MQTT
CCCBib can publish what is playing to your MQTT broker and Home Assistant picks it up with MQTT discovery. It publishes over a WebSocket so the broker needs a WebSocket listener (Mosquitto: listener 9001 and protocol websockets).
Turn Remote Control on first (Settings, Playback) because without it every command is dropped without a message. Then give the app the address and the login of the broker once with a launch command (how to send one is on the Remote control page):
luna-send -n 1 luna://com.webos.service.applicationmanager/launch \
'{"id":"org.webosbrew.cccbib","params":{"cmd":"mqtt","url":"ws://<broker>:9001","username":"<user>","password":"<password>"}}'
From Home Assistant send the same params with the system.launcher/launch command of webostv.command. username and password are optional and a password needs a username. Only ws:// and wss:// addresses are accepted. A toast on the TV says MQTT broker saved or Invalid MQTT broker address. The app connects at once and Home Assistant shows a device CCCBib with one sensor. To look from the outside: mosquitto_sub -h <broker> -u <user> -P <password> -t 'cccbib/#' -v.
| Topic | Content |
|---|---|
cccbib/availability |
online when connected and offline when the app closes (the broker sends it as the last will) |
cccbib/state |
JSON (retained) with state (playing, paused or idle) and for a talk title, link, conference, speakers, thumb, position, duration (seconds) and rate (the speed set in the app) |
homeassistant/sensor/cccbib/config |
Discovery message for one sensor called CCCBib |
It publishes when it connects and whenever a talk starts, pauses, plays on, is sought, changes speed, goes to the background or ends. The position is the one at the moment of the change and there is no periodic update. playing means the video really runs so a talk that is still jumping to its saved position (or that webOS paused in the background) says paused. The app only publishes while it runs and it recieves nothing so commands still go through the launch parameters. Turning Remote Control off disconnects it.
The broker user only needs to write two topic trees. With Mosquitto:
# mosquitto.conf
listener 9001
protocol websockets
# acl file
user cccbib
topic write cccbib/#
topic write homeassistant/sensor/cccbib/config
Create the user with mosquitto_passwd. The Home Assistant Mosquitto add-on already has a WebSocket port (1884 by default, see its documentation). Home Assistant itself needs to read cccbib/# and homeassistant/# which it does with its own login.
Removing an integration in Home Assistant may not tell the app (check the documentation of the integration). If it does not the app stays paired and keeps publishing so unpair first: send {"cmd": "mqtt"} without a url. The app publishes offline, disconnects and forgets the address and the login (a toast says MQTT broker cleared).
The retained discovery message and the last state stay on the broker so the sensor stays in Home Assistant as unavailable. To remove it completely delete the retained messages and then the device in Home Assistant:
mosquitto_pub -h <broker> -u <admin> -P <password> -r -n -t homeassistant/sensor/cccbib/config
mosquitto_pub -h <broker> -u <admin> -P <password> -r -n -t cccbib/state
mosquitto_pub -h <broker> -u <admin> -P <password> -r -n -t cccbib/availability
To add it again send the same pairing command. A refused login is not retried on its own so after fixing the user or the rights on the broker send the command again.
- Nothing happens after the command: Remote Control is off or the TV is off (a TV in standby does not get commands).
-
Invalid MQTT broker address: the address is notws://orwss://, it has a login or a#in it or a password was sent without a username. -
MQTT broker savedbut no sensor: the broker has no WebSocket listener on that port, the login is refused or the MQTT integration of Home Assistant is not set up. - Sensor
unavailableafter leaving the app: webOS closed the app and the broker sent the last will. The sensor is back when the app runs again.
The address and the login are kept in the app's storage on the TV as plain text and ws:// is not encrypted. Use a broker user that cannot do more than the two writes above and a password you use nowhere else. wss:// works if the TV trusts the certificate.