Is there a code I can use to hide devices (Make Hidden) from within dzvents.
In other words: is there a way to rename devices using dzvents.
User case:
I have an airco on/of switch and an airco temperature switch.
It is senseless to change temperature when the airco is switched off.
Compare this to to the display on the airco remote: temp, horizontal fan movement, vertical fan movement, switching between heat, cool, fan or dry; it is only visible when the airco is switched on.
Solution found:
- domoticz.devices(4).rename('Airco settings')
- domoticz.devices(4).rename('$Airco settings')
Now the question is how to let dzvents refresh the webpage.
Hide devices using dzvents
Moderator: leecollings
-
HvdW
- Posts: 663
- Joined: Sunday 01 November 2015 22:45
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Twente
- Contact:
Hide devices using dzvents
Bugs bug me.
-
HvdW
- Posts: 663
- Joined: Sunday 01 November 2015 22:45
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Twente
- Contact:
Re: Hide devices using dzvents
Hi
I made a script to hide and unhide devices.
Why?
There are a lot of devices like switches that are only used in scripts to do something.
I don't want those to appear under the tab switches.
Sometimes I want to see them, sometimes not.
Be carefull using this. Why?
If you have a switch 'My Switch' and you change the name to '$My Switch' it will not react in a script when called by 'My Switch'
When hidden or not you must use the idx of the device.
After toggling use Ctrl-F5 to effectuate hiding and appearing of devices.
I made a script to hide and unhide devices.
Why?
There are a lot of devices like switches that are only used in scripts to do something.
I don't want those to appear under the tab switches.
Sometimes I want to see them, sometimes not.
Be carefull using this. Why?
If you have a switch 'My Switch' and you change the name to '$My Switch' it will not react in a script when called by 'My Switch'
When hidden or not you must use the idx of the device.
Code: Select all
--[[
Script: Toggle Hidden/Visible Devices in Domoticz
Trigger: Switch 'Hide/unhide devices' (ON = hidden, OFF = visible)
Functionaliteit:
- Als de switch ON is, worden alle devices in devicesConfig hernoemd naar '$baseName' (hidden).
- Als de switch OFF is, worden alle devices in devicesConfig hernoemd naar 'baseName' (visible).
Wiki: https://www.domoticz.com/wiki/dzVents:_next_generation_LUA_scripting_framework
]]
-- Configuration: Vul hier de device IDX en base names in
-- VOEG DE TRIGGER SWITCH NIET TOE AAN DEZE LIJST!
local devicesConfig = {
{idx = 45, baseName = 'Auto laden'},
--{idx = 123, baseName = 'Airco settings'}, -- Vervang 123 met de echte IDX
--{idx = 124, baseName = 'Lamp keuken'}, -- Vervang 124 met de echte IDX
--{idx = 125, baseName = 'TV hoek'}, -- Vervang 125 met de echte IDX
}
-- Vul hier de naam van je trigger switch in
-- Deze switch mag NOOIT in devicesConfig staan!
local triggerSwitchName = 'Hide/unhide devices'
return {
on = {
devices = {
triggerSwitchName -- Alleen triggeren op de hide/unhide switch
}
},
logging = {
level = domoticz.LOG_INFO,
marker = "Toggle Hidden/Visible Devices"
},
execute = function(domoticz, trigger)
-- Bepaal de gewenste actie op basis van de switch staat
local hideDevices = (trigger.state == 'On')
-- Loop door alle devices in devicesConfig
for _, device in ipairs(devicesConfig) do
local currentDevice = domoticz.devices(device.idx)
if currentDevice then
local newName
if hideDevices then
-- Als de switch ON is, voeg '$' toe (hidden)
newName = '$' .. device.baseName
else
-- Als de switch OFF is, verwijder '$' (visible)
newName = device.baseName
end
-- Hernoem het device
currentDevice.rename(newName)
domoticz.log("Device '" .. device.baseName .. "' hernoemd naar '" .. newName .. "'", domoticz.LOG_INFO)
else
domoticz.log("Device met idx " .. device.idx .. " niet gevonden!", domoticz.LOG_ERROR)
end
end
end
}
Bugs bug me.
Who is online
Users browsing this forum: No registered users and 1 guest