First of all thanks to this thread so I could configure my Home Assistant instance and Mosquitto to receive the messages from the camera.
I went one step further, because I wanted to have a Switch in Home Assistant to enable/disable Sleep Mode on the camera, and guess what: it’s done by MQTT.
The first thing is that with the configuration provided in this thread, the bridge between the two MQTT servers is only one direction (from lollipop to your Mosquitto server). So you receive the messages from the camera to your Mosquitto topic, but if you send messages to that topic, the camera doesn’t receive them.
To enable bi-directional bridge the only thing needed to change is the last line:
topic # in 0 lollipop/ <main camera topic>/
to
topic # both 0 lollipop/ <main camera topic>/
Now the messages sent to the lollipop/
topic in your Mosquitto server will be received by the camera.
Next step we need to configure the Switch by itself, that means: sending the ON and OFF commands to enable and disable the Sleep Mode, and also getting the status of the Sleep Mode. Everything can be achieved using MQTT.
To enable/disable the sleep mode we need to send a json message to the lollipop/camSetting
topic.
The message should be something like:
{"method": "camSetting", "params": { "standby_mode": false }, "id": 14}
The id
attribute can have any numeric value, the only thing that changes between enabling and disabling sleep mode is the boolean value of standby_mode
attribute.
Now we need the status of the Sleep mode, we can get this from the lollipop/cameraStatus/return
topic, it publishes messages like:
42["messageReply",{"method":"cameraStatus","id":20,"params":{"appSessionId":null,"info":"owner"},"result":{"status":1,"bindSensor":"","bindSensorName":"","bindStatus":1,"temp":-1000.0,"humidity":-1000.0,"noise":60.159999999999997,"air":-1000.0,"wifiSsid":"MyWiFi","wifiQuality":82.0,"playingMusic":false,"firmwareVersion":"2022041400-g5bca956","standby_mode":false,"privacyMode":false}}]
As you can see, this is something similar to a JSON message, but it’s not exactly a JSON.
Last thing: as the messages on this topic are not retained, we need to publish a message on the lollipop/cameraStatus
topic to get the status on the previous topic. The message should be like:
{"params": { "info": "owner" }, "id": 20, "method": "cameraStatus" }
Every time you publish this message to the topic, then it returns the status on the previous topic.
So now that we know how it works, it’s time to configure the Switch!
In your configuration.yaml
, you can define it in mqtt/switch section like:
- name: "Lollipop Sleep Mode"
state_topic: "lollipop/cameraStatus/return"
value_template: "{{ 'ON' if (value[18:-1]|from_json).result.standby_mode else 'OFF' }}"
json_attributes_topic: "lollipop/cameraStatus/return"
json_attributes_template: "{{ (value[18:-1]|from_json).result|tojson }}"
command_topic: "lollipop/camSetting"
state_on: "ON"
state_off: "OFF"
payload_off: '{"method": "camSetting", "params": { "standby_mode": false }, "id": 14}'
payload_on: '{"method": "camSetting", "params": { "standby_mode": true }, "id": 14}'
unique_id: "lollipop_sleep_mode"
As you can see, the only “tricky” thing is that we need to do a substring of the returned status message to get the json formatted content, everything else is exactly what we talked before.
Only one thing remains: Create an automation to keep the status always updated.
So the triggers for the automation must be two:
- Home assistant boot
- MQTT messages on topic
lollipop/camSetting/return
The second is because, every time the standby_mode
changes (from Home Assistant or from the app), a message is sent to that topic.
No conditions are needed for this automation.
And the action must be publish a MQTT Message to lollipop/cameraStatus
as we’ve seen before:
{"params": { "info": "owner" }, "id": 20, "method": "cameraStatus" }
After this, we can reboot Home Assistant and we’ll have a Switch to control the Sleep Mode of the camera.
I hope this can be useful to somebody!