I wanted to split my sensor values for a couple of reasons:
- Easier to replace a device in Domoticz (and retaining the log) when you don't have to worry about getting a TempHum to replace your previous TempHum. Now I can just split the values into dummy devices and then update the script with the new hardware devices.
- 2. Friendly sensor names for the Dashboard. I like to give my sensors longer and more descriptive names, but it doesn't look pretty on the Dashboard.
Using the examples in this thread (and other resources), I came up with this
Code: Select all
commandArray = {}
-- Balcony
sensorTemperature, sensorHumidity, sensorHumidityStatus = otherdevices_svalues['Sensor1 (Clas Ohlson 36-4441)']:match("([^;]+);([^;]+);([^;]+)")
table.insert (commandArray, { ['UpdateDevice'] = string.format("%d|0|%.2f", otherdevices_idx['Balcony Temperature'], sensorTemperature) })
table.insert (commandArray, { ['UpdateDevice'] = string.format("%d|%d|%d", otherdevices_idx['Balcony Humidity'], sensorHumidity, sensorHumidityStatus) })
-- Bathroom
sensorTemperature, sensorHumidity, sensorHumidityStatus = otherdevices_svalues['Sensor2 (Oregon THGR810)']:match("([^;]+);([^;]+);([^;]+)")
table.insert (commandArray, { ['UpdateDevice'] = string.format("%d|0|%.2f", otherdevices_idx['Bathroom Temperature'], tonumber(sensorTemperature)) })
table.insert (commandArray, { ['UpdateDevice'] = string.format("%d|%d|%d", otherdevices_idx['Bathroom Humidity'], sensorHumidity, sensorHumidityStatus) })
-- Bedroom
sensorTemperature, sensorHumidity, sensorHumidityStatus = otherdevices_svalues['Sensor3 (Aeotec ZW100)']:match("([^;]+);([^;]+);([^;]+)")
table.insert (commandArray, { ['UpdateDevice'] = string.format("%d|0|%.2f", otherdevices_idx['Bedroom Temperature'], sensorTemperature) })
table.insert (commandArray, { ['UpdateDevice'] = string.format("%d|%d|%d", otherdevices_idx['Bedroom Humidity'], sensorHumidity, sensorHumidityStatus) })
table.insert (commandArray, { ['UpdateDevice'] = string.format("%d|0|%d", otherdevices_idx['Bedroom Lux'], otherdevices_utility['Sensor3 Lux (Aeotec ZW100)']) })
table.insert (commandArray, { ['UpdateDevice'] = string.format("%d|0|%.2f", otherdevices_idx['Bedroom UV'], otherdevices_uv['Sensor3 UV (Aeotec ZW100)']) })
-- Closet
table.insert (commandArray, { ['UpdateDevice'] = string.format("%d|0|%.2f", otherdevices_idx['Closet Temperature'], otherdevices_temperature['Sensor4 (Clas Ohlson 36-4744)']) })
-- Hallway
table.insert (commandArray, { ['UpdateDevice'] = string.format("%d|0|%.2f", otherdevices_idx['Hallway Temperature'], otherdevices_temperature['Sensor5 (Clas Ohlson 36-4744)']) })
-- Living Room
table.insert (commandArray, { ['UpdateDevice'] = string.format("%d|0|%.2f", otherdevices_idx['Living Room Temperature'], otherdevices_temperature['Sensor6 (Clas Ohlson 36-4744)']) })
-- Refrigerator/Kitchen
sensorTemperature, sensorHumidity, sensorHumidityStatus = otherdevices_svalues['Sensor7 (Clas Ohlson 36-4441']:match("([^;]+);([^;]+);([^;]+)")
table.insert (commandArray, { ['UpdateDevice'] = string.format("%d|0|%.2f", otherdevices_idx['Refrigerator Temperature'], tonumber(sensorTemperature)) })
table.insert (commandArray, { ['UpdateDevice'] = string.format("%d|%d|%d", otherdevices_idx['Kitchen Humidity'], sensorHumidity, sensorHumidityStatus) })
return commandArray
A thing to note (which I see was also part of the issue in the above posts) is that a humidity sensor uses the nValue for humidity percentage and the sValue for the "feeling" (or "status" as it's referenced in
the API/JSON wiki), whereas the temperature sensor uses the sValue only.
To be certain I understood the UpdateDevice event syntax correctly, I had to verify in
the domoticz source code, where I confirmed that index 0 was the idx, index 1 is the nValue and index 2 is the sValue:
Code: Select all
['UpdateDevice'] = idx|nValue|sValue
Also, using the "string.format" you have to keep in mind to use the correct types. In my example I've only used "%d" (digit/integer) and "%f" (float/decimal number). When using floats you can specify how many decimals like this; "%.2f" for 2 decimals, "%.5f" for 5 decimals etc. "%s" is a string (anything enclosed in 'single' or "double" quotes essentially). I forgot this in the beginning so I kept getting my temperature as integers (3 rather than 3.5 f.ex).
And one last thing.
Dumping all variables to the log is really helpful when trying to figure out what devices/events is available and what values they contain.