Page 1 of 1

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

Posted: Wednesday 21 December 2016 12:58
by Evelen
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 5236 times

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

Posted: Wednesday 21 December 2016 19:08
by mark.sellwood
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.

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

Posted: Wednesday 21 December 2016 23:35
by Evelen
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?

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

Posted: Thursday 22 December 2016 21:31
by mark.sellwood
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.

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

Posted: Saturday 09 September 2017 23:17
by briped
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.

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

Posted: Saturday 22 September 2018 7:40
by funnybu
My be someone has Dzvents example for this action? Split at temp/hum sensor into separate hum and temp devices?

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

Posted: Sunday 23 September 2018 15:58
by funnybu
It's me

DzVents script

Code: Select all

local REAL_TEMP_HUM_DEVICE = 'outdoor_temp_hum' -- Real temperature and humidity device name
local DUMMY_TEMP_DEVICE = 'outdoor_temp' -- Dummy temperature device name
local DUMMY_HUM_DEVICE = 'outdoor_hum' -- Dummy humidity device name


return {
        on = {devices = {REAL_TEMP_HUM_DEVICE}},
        logging = {
                    level = domoticz.LOG_ERROR,
                    marker = "temp_split" 
        },
        execute = function(dz, trigger )
            local virtualTemperatureSensor  = dz.devices(DUMMY_TEMP_DEVICE)
            local virtualHumiditySensor     = dz.devices(DUMMY_HUM_DEVICE)
        
            local masterTemperature         = dz.utils.round(trigger.temperature,1)
            local masterHumidity            = dz.utils.round(trigger.humidity)
            local masterHumidtyStatus       = trigger.humidityStatusValue
        
            local slaveTemperature          = dz.utils.round(virtualTemperatureSensor.temperature,1)
            local slaveHumidity             = dz.utils.round(virtualHumiditySensor.humidity)
        
            if slaveTemperature ~= masterTemperature then 
                virtualTemperatureSensor.updateTemperature(masterTemperature) 
            end
            
            if slaveHumidity ~= masterHumidity then 
                virtualHumiditySensor.updateHumidity(masterHumidity,masterHumidtyStatus)
            end    
        end
}

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

Posted: Sunday 27 October 2019 18:38
by Harald777
Hi guys,

I want to only use the temp and hum value of a multi sensor (tem, hum & baro) but cannot get that to work.
The sensor has THB1 - BTHR918, BTHGN129 as type description (Temp + Humidity + Baro).
Its a home weather station sensor and the baro value is very unreliable while temp and hum are okay.

Any tips on how to do that is much appreciated.

Greetings,

Harald

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

Posted: Monday 28 October 2019 1:47
by waaren
Harald777 wrote: Sunday 27 October 2019 18:38 I want to only use the temp and hum value of a multi sensor (tem, hum & baro) but cannot get that to work.
The sensor has THB1 - BTHR918, BTHGN129 as type description (Temp + Humidity + Baro).
Its a home weather station sensor and the baro value is very unreliable while temp and hum are okay.
Any tips on how to do that is much appreciated.
What is unclear about the previous post ? @funnybu already shared a script to split the values and update a new virtual device with these values.

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

Posted: Monday 28 October 2019 16:14
by Harald777
waaren wrote:
Harald777 wrote: Sunday 27 October 2019 18:38 I want to only use the temp and hum value of a multi sensor (tem, hum & baro) but cannot get that to work.
The sensor has THB1 - BTHR918, BTHGN129 as type description (Temp + Humidity + Baro).
Its a home weather station sensor and the baro value is very unreliable while temp and hum are okay.
Any tips on how to do that is much appreciated.
What is unclear about the previous post ? @funnybu already shared a script to split the values and update a new virtual device with these values.
Unfortunately not that clear to me. Will do some more investigation.

Verstuurd vanaf mijn Nexus 5X met Tapatalk


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

Posted: Sunday 03 November 2019 11:31
by Gravityz
thanks funnybu

just got my Digoo R8S sensor and implemented your script.

seems to be working nicely. at first it did not update but now it does