Zigbee2mqtt light default value

Ls,

I’ve searched the web and the forum but not found a solution for my problem which is the following:
I have zigbee lamps connected to Hass via zigbee2mqtt and this is working.

  1. By night a sensor is controlling a lamp by setting it to 10% and a specific color
    2 In the morning, when I push a switch on hass dashboard, I want the lamp on the 100% and white color.
    This must be done by sending a mqtt msg with state on, color xxx but I cannot find how to send this mqtt msg from a button on the dashboard.
    Do I need a script, or something in conf file of z2m or something else.
    Please can I have a hint to put me in the right direction.
    Thanks in advance.

This would be done with a service call service: light.turn_on
You can add a button in the UI and at tap action select call service and type in light.turn_on From there you can select the device and set all kind of stuff like brightness and color/ ect

Any reason this has to be done via a MQTT message? If you have Zigbee2mqtt then the lamp should be a device in HA

From the UI - do this :

Here is the YAML :

service: mqtt.publish
data:
  qos: "2"
  retain: false
  payload: "{   \"color\": {     \"r\": 0,     \"g\": 0,     \"b\": 0   },   \"brightness\": 0 }"
  topic: zigbee2mqtt_office/Living Room Lights/set

Just make sure you get the topic right (use MQTTExplorer to see) so it’s zigbee2mqtt/your light/set

thanks for the solution but I prefer mqtt msg because I control all my devices via mqtt and node red on a separate server.

I tryed this solution but something is wrong in the payload. The mqtt client returns:
*** PAYLOAD IS NOT VALID JSON DATA ***

Unexpected character (‘p’ (code 112)): expected a valid value (number, String, array, object, ‘true’, ‘false’ or ‘null’)
at [Source: java.io.StringReader@30a77324; line: 1, column: 4]

Looks like the UI has messed with the format :slight_smile:

Try this :

{   "color": {     "r": 0,     "g": 0,     "b": 0   },   "brightness": 0 }

I already found the problem I also copied “payload:”.
So another lesson not to blindly copy and paste !
Thanks very much for your help. It is working.

1 Like