OK, lets try
First of all You have to prepare the environment to build domoticz from source, since a little change is required in its code. Use this manual:
https://www.domoticz.com/wiki/Build_Dom ... rom_source
Then, follow the steps below:
1. Alter the following section in dev-domoticz/hardware/OpenZWave.cpp (this will force domoticz to send value 99 instead of 255 for the "Open" command:
Code: Select all
//dimmable/color light device
if ((svalue > 99) && (svalue != 255))
svalue = 99;
if (GetValueByCommandClassIndex(pDevice->nodeID, (uint8_t)instanceID, COMMAND_CLASS_SWITCH_MULTILEVEL, ValueID_Index_SwitchMultiLevel::Level, vID) == true)
{
std::string vLabel = m_pManager->GetValueLabel(vID);
// Special case for Fibaro FGR-223 (Roller Shutter 3)
if ( (pDevice->Manufacturer_id == 0x010F) && (pDevice->Product_id == 0x1000) && (pDevice->Product_type == 0x0303) ) {
if ( svalue == 255 ) {
pDevice->intvalue = 255;
svalue = 99;
}
}
else {
pDevice->intvalue = svalue;
}
2. Save changes and build domoticz from source.
3. Redirect domoticz logs to a separate file. Do it using rsyslog configuration. Prepare /etc/rsyslog.d/domoticz.conf:
Code: Select all
if $programname == 'domoticz' then /var/log/domoticz.log
& stop
Restart rsyslog.
4. Stop domoticz process, copy built domoticz executable to Your running domoticz folder (first make backup of the original one
) and start domoticz again.
5. Prepare shell script (i.e in scripts folder) that will constantly parse domoticz.log (lets call it FibaroLevel.sh). Script should tail -F domoticz.log and look for phrase: 'Domoticz has send a Switch command!, Level:'. In this line You will always find both NodeID and shutter level to be set. You have to get both values from this line (I use string substitution for this). Then You have to map NodeID to Domoticz DeviceName pointing to Your shutter switch device (You'll need it in a moment). NodeID You will find in ZWave controller configuration menu and DeviceName in Devices menu. Having both values You'll be ready to run script from the following point (SetValues.sh) with both values as variables. Important - SetValues.sh has to be forked/run in background ! (./SetValues DEVICE LEVEL &). Alternatively You can run both sleep and curl commands from SetValue.sh right from FibaroLevel.sh - for instance like this: (sleep 30; curl ......)&
Script can look like this:
Code: Select all
#!/bin/bash
DEVICE=""
LEVEL=""
tail -F /var/log/domoticz.log | while read LINE; do #Point to Your actual domoticz.log
if [[ $LINE == *'Domoticz has send a Switch command!, Level:'* ]]; then
TMP=${LINE#*ID: }
NODEID=${TMP% (*}
TMP=${LINE#*Level: }
LEVEL=${TMP%,*}
if [[ $LEVEL == "255" ]]; then
LEVEL="99"
fi
case $NODEID in #Use Your nodeids and devicenames !
2) DEVICE='Shutter1';;
3) DEVICE='Shutter2';;
4) DEVICE='Shutter3';;
esac
/opt/domoticz/scripts/SetValues.sh "${DEVICE}" ${LEVEL} &
DEVICE=""
LEVEL=""
fi
done
6. Prepare another shell script (i.e. SetValues.sh), that will:
a) wait a few seconds
b) run domoticz dzVents/Custom Events script to set the required shutter level
The script can look like this:
Code: Select all
#!/bin/bash
DEVICE=$1
LEVEL=$2
sleep 30 #wait 30s to set level value in domoticz
curl -ks -d "type=command¶m=customevent&event=FibaroLevelUpdate&data=[{\"DEVICE\":\"${DEVICE}\",\"LEVEL\":\"${LEVEL}\"}]" -X POST https://127.0.0.1/json.htm
where: $DEVICE keeps DeviceName and $LEVEL of course the required level
7. Now the final part: prepare dzVents->Custom events script, that will look like this:
Code: Select all
return {
on = {
customEvents = { 'FibaroLevelUpdate' }
},
logging = {
level = domoticz.LOG_DEBUG --this is optional in order to get more info
},
data = { },
execute = function(domoticz, triggeredItem)
if ( triggeredItem.data[1].LEVEL == '99' ) then --Shutter opened
nValue=1
sValue=100
elseif ( triggeredItem.data[1].LEVEL == '0' ) then --Shutter closed
nValue=0
sValue=0
else --Shutter leveled
nValue=2
sValue=triggeredItem.data[1].LEVEL
end
domoticz.log('***** Setting nValue='..nValue..', sValue='..sValue.." for: "..triggeredItem.data[1].DEVICE, domoticz.LOG_INFO)
domoticz.devices(triggeredItem.data[1].DEVICE).setValues(nValue, sValue) --this one actually sets the correct values without moving the shutter again.
end
}
8. Run the main script forever: ./FibaroLevel.sh &
And You're done
Simple - isn't it ?