micolous / cbus

Use Python to communicate with a Clipsal C-Bus PCI or CNI! Includes MQTT bridge (for Home Assistant), PCI simulator, and reverse engineering notes.
http://cbus.readthedocs.org/
GNU Lesser General Public License v3.0
49 stars 27 forks source link

Ramped OFF from C-Bus that produces ON with brightness zero? #43

Open sgraystar opened 1 year ago

sgraystar commented 1 year ago

How do people deal with ramped OFF commands from C-Bus that indicate the light is ON with brightness zero?

I am a newbie to HA, so have installed the cbus2mqtt add-on that uses cmqttd and run with default HA MQTT Discovery. All C-Bus light GA’s appear in HA and all is good. Thank you to all for the past work.

The question comes about when a GA is ramped to OFF in C-Bus, e.g. in a Goodbye Scene. The MQTT info received in HA shows the Binary Sensor as OFF, and the Light as ON with Brightness zero and ramp duration. It is odd to watch lights in HA all turn on when C-Bus turns them all off. It gets more mixed up when also using Homekit Bridge , where the lights in homekit now show 100% ON …

How do people deal with this?

damon-atkins commented 1 year ago

If you look at your C-BUS Dimmer (in your switchboard), what is the status of the "green light" for circuit.

sgraystar commented 1 year ago

The dimmer led matches the indoor light, on during the ramp then off.

Using MQTT Explorer you can see that when C-Bus issues the ramp to zero command it results in cmqttd updating "homeassistant/light/cbus_10/state" with "{"state": "ON", "brightness": 0, "transition": 8, "cbus_source_addr": 54}" In HA this causes the light to turn back on, at the previous retain level.

Since this has been around for a while I wondered how other people handled it. Maybe it has something to do with the default HA Discovery and I should try a lights.yaml configuration?

damon-atkins commented 1 year ago

Sounds like brightness of 0 needs report a status of "OFF". If you switch off a Dimmer light (without ramp) whats the brightness reported as.

sgraystar commented 1 year ago

This the wanted end state, so switching off without a ramp also reports brightness 0, {"state": "OFF", "brightness": 0, "transition": 0, "cbus_source_addr": 54}

bdnstn commented 1 year ago

My solution uses CgateWeb, which publishes an OFF when the level is 0 and an ON when the level is > 0. I guess that is done to avoid the issue you are seeing.

sgraystar commented 1 year ago

Agreed. The debug log shows HA ignores the invalid brightness, and continues with the ON.

2023-07-19 08:49:21.254 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received message on homeassistant/light/cbus_10/state (qos=0): b'{"state": "ON", "brightness": 0, "transition": 0, "cbus_source_addr": null}' 2023-07-19 08:49:21.254 DEBUG (MainThread) [homeassistant.components.mqtt.light.schema_json] Ignoring zero brightness value for entity light.bed3_lvs_x_4 2023-07-19 08:49:21.255 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received message on homeassistant/binary_sensor/cbus_10/state (qos=0): b'OFF'

Suggested change around cmqttd.py line 259

state = 'ON' if level > 0 else 'OFF' self.publish(state_topic(group_addr,app_addr), { 'state': state,