Split at "temp/hum" sensor into separat hum and temp devices?

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.
Post Reply
Evelen
Posts: 261
Joined: Thursday 09 July 2015 12:03
Target OS: Linux
Domoticz version: 2.4538
Location: Norway
Contact:

Split at "temp/hum" sensor into separat hum and temp devices?

Post by Evelen » Wednesday 21 December 2016 13:58

Ok, I Run Impreihome and it i not possible to change the icon for temp/Humidity devices, but it is possible on just temp sensors. (Weird, but that's how it is).

therfor I want to split ut my hum/temp sensors, or transfer the temp data to a dummy, same for Humidity.

Is this posible in a way?
Uten navn.png
Uten navn.png (51.21 KiB) Viewed 704 times

mark.sellwood
Posts: 23
Joined: Tuesday 04 March 2014 11:33
Target OS: Raspberry Pi
Domoticz version:
Location: Surrey, UK
Contact:

Re: Split at "temp/hum" sensor into separat hum and temp devices?

Post by mark.sellwood » Wednesday 21 December 2016 20:08

I do this with my Oregon Scientific Thermometer & Humidity Sensor Remote Sensor & Aeotec Multi Sensor to split out the Thermometer & Humidity in to separate values.

The script below I use to split my Oregon & Aeotec but it may not work for you as it depends on the format of the raw data from the sensor, the Oregon & Aeotec both send there data in different formats.
The Oregon gets reported as temp;hum so they are split based on a match, where as the Aeotec reports as something different.
I know it took me some time with trial & error to get it working.
First you need to add the new virtual Temperature & Humidity sensors, make a note of there idx's

In the script you define the idx's of the virtual sensors to update.
eg local FGTidx = 166 --idx of virtual temp sensor "Front Garden Temperature"

"Front Garden" is the name of my Oregon sensor & "Lounge" is the name of the Aeotec sensor

Code: Select all

local Front Garden Temperature idx = 166 --idx of virtual temp sensor "Front Garden Temperature"
local Front Garden Humidity idx= 167 --idx of virtual humidity sensor "Front Garden Humidity"
local Lounge Temperature idx= 200 --idx of virtual temp sensor "Multi Sensor 1 Temperature"
local Lounge Humidity idx= 201 --idx of virtual humidity sensor "Multi Sensor 1 Humidity"

commandArray = {}
time = os.date("*t")
if((time.min % 10)==0)then

	function round(num, idp) -- Credits go to Martin Rourke, I used his function.
		local mult = 10^(idp or 1)
		return math.floor(num * mult + 0.5) / mult
	end
-- Split Oregon
sWeatherTemp, sWeatherHumidity = otherdevices_svalues['Front Garden']:match("([^;]+);([^;]+)")

sWeatherTemp = tonumber(sWeatherTemp)
commandArray[1]={['UpdateDevice'] = Front Garden Temperature idx .. '|0|' .. tostring(sWeatherTemp)}

sWeatherHumidity = tonumber(sWeatherHumidity)
commandArray[2]={['UpdateDevice'] = Front Garden Humidity idx.. '|' .. (sWeatherHumidity)  .. '|0'}


--Split Aeotec
MS1Temperature = round(otherdevices_temperature['Lounge'])
commandArray[3]={['UpdateDevice'] = Lounge Temperature idx.. '|0|' .. tostring(MS1Temperature)}

MS1humidity = otherdevices_humidity['Lounge']
commandArray[4]={['UpdateDevice'] = Lounge Humidity idx.. '|' .. (MS1humidity)  .. '|0'}

end

return commandArray
Please note that this is a Time script & it runs every 10 mins.
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.

Evelen
Posts: 261
Joined: Thursday 09 July 2015 12:03
Target OS: Linux
Domoticz version: 2.4538
Location: Norway
Contact:

Re: Split at "temp/hum" sensor into separat hum and temp devices?

Post by Evelen » Thursday 22 December 2016 0:35

thanks for replay, have modified the script a little but noting i happening, just errors in console.

Code: Select all

2016-12-21 23:33:00.194 Error: EventSystem: in Temp/Fukt Splitter: [string "local temperature_dummy_idx = 233 ..."]:16: expected near 'end'
Running the scripts as "time" without det time-function inckluded (so every minute.

Code: Select all

local temperature_dummy_idx =   233
local humidity_dummy_idx =      234

commandArray = {}

-- Split
sWeatherTemp, sWeatherHumidity = otherdevices_svalues['3 - Stue/Kjøkken']:match("([^;]+);([^;]+)")

sWeatherTemp = tonumber(sWeatherTemp)
commandArray[1]={['UpdateDevice'] = temperature_dummy_idx .. '|0|' .. tostring(sWeatherTemp)}

sWeatherHumidity = tonumber(sWeatherHumidity)
commandArray[2]={['UpdateDevice'] = humidity_dummy_idx.. '|' .. (sWeatherHumidity)  .. '|0'}


end

return commandArray
Devices:

"3 - Stue/Kjøkken" = idx 15 <-this one is the real device
"3 - Stue/Kjøkken - Luftfuktighet" = idx 234
"3 - Stue/Kjøkken - Temperatur" = idx 233

idx 15:
Current state: 23.6;30;2
sValues: 23.6;30;2

idx 234 (dummy):
Current state: 1
sValues: 1

idx 233 (dummy):
Current state: 0.0
sValues: 0.0

Any idea?

mark.sellwood
Posts: 23
Joined: Tuesday 04 March 2014 11:33
Target OS: Raspberry Pi
Domoticz version:
Location: Surrey, UK
Contact:

Re: Split at "temp/hum" sensor into separat hum and temp devices?

Post by mark.sellwood » Thursday 22 December 2016 22:31

It looks as if your sensor is returning 3 bits of data (23.6;30;2) so I think you may need to edit the following line

Code: Select all

existing
sWeatherTemp, sWeatherHumidity = otherdevices_svalues['3 - Stue/Kjøkken']:match("([^;]+);([^;]+)")

New
sWeatherTemp, sWeatherHumidity, sWeatherOther = otherdevices_svalues['3 - Stue/Kjøkken']:match("([^;]+);([^;]+);([^;]+)")
I know it took me a couple of days to sort it out with much trial & error.
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.

briped
Posts: 4
Joined: Monday 14 August 2017 13:41
Target OS: Linux
Domoticz version:
Contact:

Re: Split at "temp/hum" sensor into separat hum and temp devices?

Post by briped » Saturday 09 September 2017 23:17

I wanted to split my sensor values for a couple of reasons:
  1. 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. 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.

Post Reply

Who is online

Users browsing this forum: freakshock and 6 guests