Hi to all.
I'm trying to get the values of a virtual dimmer (RGB color and master slider), so I can push them via mqtt.
The question is: how can I read this values and put them in variables?
Thanks so much for your help.
Gianluca
RGB Color from Dimmer [Solved]
Moderator: leecollings
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: RGB Color from Dimmer
Reading is the easy part.
Question is what needs to be done with the values ?
Code: Select all
return
{
on =
{
devices =
{
3137, -- idx or 'name' of your RGBW device
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'getColor',
},
execute = function(dz, item)
dz.utils.dumpTable(item.getColor() )
dz.log(item.name ..'; color = ' .. dz.utils.toJSON(item.getColor()),dz.LOG_DEBUG)
dz.log(item.name ..'; dimLevel = ' .. item.level,dz.LOG_DEBUG)
end
}
- Spoiler: show
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 9
- Joined: Monday 11 September 2017 12:42
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: RGB Color from Dimmer
Thanks for the quick reply. I will try it asap.
I've a modified aqaura gateway (https://github.com/cadavre/miio_gateway) and I'm trying to send, via mqtt the commands to change the colors. I've already achieved the on off (via node red), now I'm trying to change the color.
Do you kn ow a simpler way ?
Thank you!
I've a modified aqaura gateway (https://github.com/cadavre/miio_gateway) and I'm trying to send, via mqtt the commands to change the colors. I've already achieved the on off (via node red), now I'm trying to change the color.
Do you kn ow a simpler way ?
Thank you!
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: RGB Color from Dimmer
What is the mqtt command you are looking for?gian72 wrote: I've a modified aqaura gateway (https://github.com/cadavre/miio_gateway) and I'm trying to send, via mqtt the commands to change the colors. I've already achieved the on off (via node red), now I'm trying to change the color.
Do you know a simpler way ?
Thank you!
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 9
- Joined: Monday 11 September 2017 12:42
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: RGB Color from Dimmer
Code: Select all
return
{
on =
{
devices =
{
201, -- idx or 'name' of your RGBW device
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'getColor',
},
execute = function(dz, item)
dz.utils.dumpTable(item.getColor() )
dz.log(item.name ..'; color = ' .. dz.utils.toJSON(item.getColor()),dz.LOG_DEBUG)
dz.log(item.name ..'; dimLevel = ' .. item.level,dz.LOG_DEBUG)
comando = 'mosquitto_pub -h mqttserver -t /mihome/brightness -m ' ..item.level
os.execute(comando)
end
}
So what i'm trying right now is how to get the RGB value in a format like 'fffff' so I put it in a command like
Code: Select all
comando = 'mosquitto_pub -h mqttserver -t /mihome/rgb -m ' ..item.SOMETHING
Gianluca
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: RGB Color from Dimmer
Can you test this?gian72 wrote: ↑Tuesday 25 August 2020 21:14 What i'm trying right now is how to get the RGB value in a format like 'fffff' so I put it in a command likeand to have the item.SOMETHING containing the rgb value.Code: Select all
comando = 'mosquitto_pub -h mqttserver -t /mihome/rgb -m ' ..item.SOMETHING
Code: Select all
return
{
on =
{
devices =
{
201, -- idx or 'name' of your RGBW device
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'sendColor',
},
execute = function(dz, item)
local mqttServer = '192.168.192.116' -- Change to IP or name of your MQTT server
local color = item.getColor()
local function osCommand(cmd)
dz.log('Executing Command: ' .. cmd,dz.LOG_DEBUG)
local fileHandle = assert(io.popen(cmd .. ' 2>&1 || echo ::ERROR::', 'r'))
local commandOutput = assert(fileHandle:read('*a'))
local returnTable = {fileHandle:close()}
if commandOutput:find '::ERROR::' then -- something went wrong
dz.log('Error ==>> ' .. tostring(commandOutput:match('^(.*)%s+::ERROR::') or ' ... but no error message ' ) ,dz.LOG_ERROR)
else -- all is fine!!
dz.log('ReturnCode: ' .. returnTable[3] .. '\ncommandOutput:\n' .. commandOutput, dz.LOG_DEBUG)
end
return commandOutput,returnTable[3] -- rc[3] contains returnCode
end
local function toHex(...)
local hex = ''
for _, rgb in ipairs({...}) do
hex = hex .. string.format('%02X',rgb) -- use string.format('%02x',rgb) if you need lower case hex
end
return hex
end
local function createMQTT(server, topic, message)
return 'mosquitto_pub -h ' .. server .. ' -t ' .. topic ..' -m ' .. message
end
osCommand( createMQTT( mqttServer, '/mihome/brighness', item.level ) )
osCommand( createMQTT( mqttServer, '/mihome/rgb', toHex(color.r, color.g, color.b ) ) )
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 9
- Joined: Monday 11 September 2017 12:42
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: RGB Color from Dimmer [Solved]
Works great!
The functions toHex and osCommand opened my mind on how dzVents is working .
Thanks so much for the solution!
Gianluca
The functions toHex and osCommand opened my mind on how dzVents is working .
Thanks so much for the solution!
Gianluca
Who is online
Users browsing this forum: No registered users and 1 guest