Why switchOn sends brightness:254 instead of state:on?

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
dariann
Posts: 5
Joined: Saturday 02 September 2023 14:07
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: PL
Contact:

Why switchOn sends brightness:254 instead of state:on?

Post by dariann »

Hi All,

I have a power supply driven by zigbee2mqtt which is activated by sending data to the "zigbee2mqtt/pwr_bookshelf1/set" topic. I am toggling its state by "switchOn" and "switchOff" like in this script:

Code: Select all

return {
	on = {
		devices = {
			'btn_square1_action_on',
			'btn_square1_action_off'
		}
	},
	logging = {
		level = domoticz .LOG_INFO,
		marker = 'btsqonoff',
	},
	execute = function(dz, dev)
		dz. log('Device ' .. dev .name .. ' was changed with value: ' .. dev .state, dz .LOG_INFO)
		if (dev .state == 'On') then
		    dz. devices('pwr_bookshelf1').switchOn()
		else
		    dz. devices('pwr_bookshelf1').switchOff()
	    end
	end
}
On "switchOff()" call I see {"state": "OFF"} in the topic payload, but on "switchOn" call see {"brightness": 254}. Does anyone know why? I expected {"state": "ON"}, but I don't know how to change it. With "brightness" set directly, my led light is turning on instantly, while with "state" it does smoothly.

I suppose that it may be somehow connected with device type, but I am not sure. Anyway, at Domoticz devices list, the "pwr_bookshelf1" device type is "Light/Switch" and subtype is "Switch".

Thanks!
dariann
Posts: 5
Joined: Saturday 02 September 2023 14:07
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: PL
Contact:

Re: Why switchOn sends brightness:254 instead of state:on?

Post by dariann »

After some digging, I have noticed that on "Switches" dashboard I have a switch "pwr_bookshelf1" with description "Light/Switch, Switch, Dimmer", so I clicked "edit" and changed "Switch Type" from "Dimmer" to "On/Off". As a result, I started getting payload {"state": "ON"} as expected, but dimmer functionality was gone.
Does anyone know how to preserve expected payload with dimmer functionality?
User avatar
waltervl
Posts: 5853
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Why switchOn sends brightness:254 instead of state:on?

Post by waltervl »

Why do you want to know this? Do you want to interfere with the Domoticz/Zigbee2MQtt interface?
You can go the the MQTT AUtodiscover hardware source code to find the logic: https://github.com/domoticz/domoticz/bl ... scover.cpp

Also check the MQTT AD documentation for switch/light: https://www.home-assistant.io/integrati ... son-schema
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
dariann
Posts: 5
Joined: Saturday 02 September 2023 14:07
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: PL
Contact:

Re: Why switchOn sends brightness:254 instead of state:on?

Post by dariann »

Because of the behavior "pwr_bookshelf1" which is different depending on the payload. In case it is:
  • {"state": "ON"}, the LED light is turning on smoothly
  • {"brightness": 254"}, the LED light is turning on instantly
I would like to turn it on smoothly instead of instantly, thus my question. Is it feasible? Or, maybe there is an other way?
User avatar
jvdz
Posts: 2328
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Why switchOn sends brightness:254 instead of state:on?

Post by jvdz »

What is the discovery mqtt message content for this device as that is used to determine what to send for On?
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
dariann
Posts: 5
Joined: Saturday 02 September 2023 14:07
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: PL
Contact:

Re: Why switchOn sends brightness:254 instead of state:on?

Post by dariann »

Could you tell me which topic of zegbee2mqtt says that?

For instance, using MQTT Explorer I found this one:

* homeassistant/select/0x84fd27fffe47d363/power_on_behavior/config

Code: Select all

{
	"availability": [
		{
			"topic": "zigbee2mqtt/bridge/state",
			"value_template": "{{ value_json.state }}"
		},
		{
			"topic": "zigbee2mqtt/pwr_bookshelf1/availability",
			"value_template": "{{ value_json.state }}"
		}
	],
	"availability_mode": "all",
	"brightness": true,
	"brightness_scale": 254,
	"command_topic": "zigbee2mqtt/pwr_bookshelf1/set",
	"device": {
		"identifiers": [
			"zigbee2mqtt_0x84fd27fffe47d363"
		],
		"manufacturer": "IKEA",
		"model": "TRADFRI driver for wireless control (30 watt) (ICPSHC24-30EU-IL-1)",
		"name": "pwr_bookshelf1",
		"sw_version": "1.2.245"
	},
	"effect": true,
	"effect_list": [
		"blink",
		"breathe",
		"okay",
		"channel_change",
		"finish_effect",
		"stop_effect"
	],
	"name": "pwr_bookshelf1",
	"schema": "json",
	"state_topic": "zigbee2mqtt/pwr_bookshelf1",
	"unique_id": "0x84fd27fffe47d363_light_zigbee2mqtt"
}
and this one:
* homeassistant/light/0x84fd27fffe47d363/light/config

Code: Select all

{
	"availability": [
		{
			"topic": "zigbee2mqtt/bridge/state",
			"value_template": "{{ value_json.state }}"
		},
		{
			"topic": "zigbee2mqtt/pwr_bookshelf1/availability",
			"value_template": "{{ value_json.state }}"
		}
	],
	"availability_mode": "all",
	"brightness": true,
	"brightness_scale": 254,
	"command_topic": "zigbee2mqtt/pwr_bookshelf1/set",
	"device": {
		"identifiers": [
			"zigbee2mqtt_0x84fd27fffe47d363"
		],
		"manufacturer": "IKEA",
		"model": "TRADFRI driver for wireless control (30 watt) (ICPSHC24-30EU-IL-1)",
		"name": "pwr_bookshelf1",
		"sw_version": "1.2.245"
	},
	"effect": true,
	"effect_list": [
		"blink",
		"breathe",
		"okay",
		"channel_change",
		"finish_effect",
		"stop_effect"
	],
	"name": "pwr_bookshelf1",
	"schema": "json",
	"state_topic": "zigbee2mqtt/pwr_bookshelf1",
	"unique_id": "0x84fd27fffe47d363_light_zigbee2mqtt"
}
or maybe this one (I just left the data of "pwr_bookshelf1" and cut others):
* zigbee2mqtt/bridge/devices

Code: Select all

...
	{
		"date_code": "20170529",
		"definition": {
			"description": "TRADFRI driver for wireless control (30 watt)",
			"exposes": [
				{
					"features": [
						{
							"access": 7,
							"description": "On/off state of this light",
							"name": "state",
							"property": "state",
							"type": "binary",
							"value_off": "OFF",
							"value_on": "ON",
							"value_toggle": "TOGGLE"
						},
						{
							"access": 7,
							"description": "Brightness of this light",
							"name": "brightness",
							"property": "brightness",
							"type": "numeric",
							"value_max": 254,
							"value_min": 0
						}
					],
					"type": "light"
				},
				{
					"access": 2,
					"description": "Triggers an effect on the light (e.g. make light blink for a few seconds)",
					"name": "effect",
					"property": "effect",
					"type": "enum",
					"values": [
						"blink",
						"breathe",
						"okay",
						"channel_change",
						"finish_effect",
						"stop_effect"
					]
				},
				{
					"access": 7,
					"description": "Controls the behavior when the device is powered on after power loss",
					"name": "power_on_behavior",
					"property": "power_on_behavior",
					"type": "enum",
					"values": [
						"off",
						"on",
						"toggle",
						"previous"
					]
				},
				{
					"access": 1,
					"description": "Link quality (signal strength)",
					"name": "linkquality",
					"property": "linkquality",
					"type": "numeric",
					"unit": "lqi",
					"value_max": 255,
					"value_min": 0
				}
			],
			"model": "ICPSHC24-30EU-IL-1",
			"options": [
				{
					"access": 2,
					"description": "Controls the transition time (in seconds) of on/off, brightness, color temperature (if applicable) and color (if applicable) changes. Defaults to `0` (no transition).",
					"name": "transition",
					"property": "transition",
					"type": "numeric",
					"value_min": 0
				},
				{
					"access": 2,
					"description": "State actions will also be published as 'action' when true (default false).",
					"name": "state_action",
					"property": "state_action",
					"type": "binary",
					"value_off": false,
					"value_on": true
				}
			],
			"supports_ota": true,
			"vendor": "IKEA"
		},
		"disabled": false,
		"endpoints": {
			"1": {
				"bindings": [],
				"clusters": {
					"input": [
						"genBasic",
						"genIdentify",
						"genGroups",
						"genScenes",
						"genOnOff",
						"genLevelCtrl",
						"haDiagnostic",
						"touchlink"
					],
					"output": [
						"genScenes",
						"genOta",
						"genPollCtrl",
						"touchlink"
					]
				},
				"configured_reportings": [],
				"scenes": []
			}
		},
		"friendly_name": "pwr_bookshelf1",
		"ieee_address": "0x84fd27fffe47d363",
		"interview_completed": true,
		"interviewing": false,
		"manufacturer": "IKEA of Sweden",
		"model_id": "TRADFRI Driver 30W",
		"network_address": 58868,
		"power_source": "Mains (single phase)",
		"software_build_id": "1.2.245",
		"supported": true,
		"type": "Router"
	}
]
dariann
Posts: 5
Joined: Saturday 02 September 2023 14:07
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: PL
Contact:

Re: Why switchOn sends brightness:254 instead of state:on?

Post by dariann »

I haven't found solution, so I used Node-RED for this and it works very well, so maybe this message thread should be placed in different topic? Maybe which is about Zigbee integration with Domoticz, but I am not sue.

Anyway, below is a screenshot of Node-RED nodes which I used. Unfortunately, my Ikea button states:
https://www.zigbee2mqtt.io/devices/E1743.html
are recognized in different topics by zigbee2mqtt, but not JSON payload. However, using change nodes I replaced payload with required by power driver:
https://www.zigbee2mqtt.io/devices/ICPS ... -IL-1.html
and it works as I wanted.
nodered_pwr.png
nodered_pwr.png (106.23 KiB) Viewed 471 times
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest