Writing temperature til text file Topic is solved
Moderator: leecollings
-
- Posts: 2
- Joined: Wednesday 19 August 2020 21:34
- Target OS: Windows
- Domoticz version:
- Contact:
Writing temperature til text file
Hi folks, I am a newbee using domoticz on Windows 10 to read four thermometers and control three switches. For my Blue Iris camera surveillance system, I need regularly (every 15 minutes or so) to write a temperature and humidity to two text files. What is the best way to accomplish this?
I hope for your patience if it's a stupid question
I hope for your patience if it's a stupid question
- psubiaco
- Posts: 194
- Joined: Monday 20 August 2018 9:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Italy
- Contact:
Re: Writing temperature til text file
Hi Tandersen,
it's easy to write a LUA script that regularly write the temperature value on a text file
You have to create the script file domoticz/scripts/lua/script_time_temperature.lua
within something like this:
This simple script will write the temperature every minute. I did not try it, so it's possible that it does not work!!
Regards.
Paolo
it's easy to write a LUA script that regularly write the temperature value on a text file
You have to create the script file domoticz/scripts/lua/script_time_temperature.lua
within something like this:
Code: Select all
file=io.open(/path/filename,'w')
-- replace /path/filename with the file that should be written
io.output(file)
io.write("Temperature="..otherdevices_svalues['Temperature_devicename'])
-- Replace Temperature_devicename with the name of temperature device in Domoticz
Regards.
Paolo
Paolo
--
I use DomBus modules to charge EV car, get a full alarm system, control heat pump, fire alarm detection, lights and much more. Video
Facebook page - Youtube channel
--
I use DomBus modules to charge EV car, get a full alarm system, control heat pump, fire alarm detection, lights and much more. Video
Facebook page - Youtube channel
-
- Posts: 2
- Joined: Wednesday 19 August 2020 21:34
- Target OS: Windows
- Domoticz version:
- Contact:
Re: Writing temperature til text file
H psubiaco,
Thanks so much for your hint. It took me a while to get back because of other important stuff but I have now added your script to the Lua file, so it runs automatically. My sensor gives out both temperature and humidity, so I had to add extraction of a substring but apart from that it worked beautifully:
It would have been enough to write this file every 15 minutes and not every 1 minute but of course that would be more complicated.
Best regards from Sweden
Thanks so much for your hint. It took me a while to get back because of other important stuff but I have now added your script to the Lua file, so it runs automatically. My sensor gives out both temperature and humidity, so I had to add extraction of a substring but apart from that it worked beautifully:
Code: Select all
print('Executing script_time_logForBI')
commandArray = {}
file1=io.open('C:/Users/User/Documents/Light control/c-programs/readThermometersNew/temperature.txt','w')
io.output(file1)
print(otherdevices_svalues)
io.write(string.sub(otherdevices_svalues['Outdoor'],1,4).."°C")
file2=io.open('C:/Users/User/Documents/Light control/c-programs/readThermometersNew/humidity.txt','w')
io.output(file2)
print(otherdevices_svalues)
io.write(string.sub(otherdevices_svalues['Outdoor'],6,7).."%RH")
return commandArray
Best regards from Sweden
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Writing temperature til text file
can you try with this ?
Code: Select all
print('Executing script_time_logForBI')
local executeAt = { 1, 17, 31, 47 } -- minutes the script need to execute
local function tableContains(t, v)
for _, value in pairs(t) do
if v == value then return true end
end
return false
end
commandArray = {}
if tableContains(executeAt, math.floor(os.date('%M'))) then
file1=io.open('C:/Users/User/Documents/Light control/c-programs/readThermometersNew/temperature.txt','w')
io.output(file1)
print(otherdevices_svalues)
io.write(string.sub(otherdevices_svalues['Outdoor'],1,4).."°C")
file2=io.open('C:/Users/User/Documents/Light control/c-programs/readThermometersNew/humidity.txt','w')
io.output(file2)
print(otherdevices_svalues)
io.write(string.sub(otherdevices_svalues['Outdoor'],6,7).."%RH")
end
return commandArray
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- frank666
- Posts: 17
- Joined: Monday 07 December 2020 10:11
- Target OS: Linux
- Domoticz version: 2024.7
- Location: San Marino
Re: Writing temperature til text file
thank you for your suggestions, i was able to publish the data of a bmp280 sensor online.
I would also like to report the date and time of detection but I can't find the variable in domoticz.
As I can do, I enclose a screenshot that shows which data I need.
I would also like to report the date and time of detection but I can't find the variable in domoticz.
As I can do, I enclose a screenshot that shows which data I need.
Code: Select all
print('Executing script_time_logForBI')
local executeAt = { 1, 6, 12, 18, 24, 30, 36, 42, 48, 54, 59 } -- minutes the script need to execute
local function tableContains(t, v)
for _, value in pairs(t) do
if v == value then return true end
end
return false
end
commandArray = {}
if tableContains(executeAt, math.floor(os.date('%M'))) then
file1=io.open('/tmp/temperature.js','w')
io.output(file1)
print(otherdevices_svalues)
io.write "document.write ('Temperature:"
io.write (string.sub(otherdevices_svalues['bmp280'],1,4).."°C Pressure sea level:")
io.write(string.sub(otherdevices_svalues['bmp280'],13,16).."Hpa ")
io.write "')"
end
return commandArray
Domoticz running on Docker,Orange Pi Zero Plus
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Writing temperature til text file
This should do it
Code: Select all
print('Executing script_time_logForBI')
local executeAt = { 1, 6, 12, 18, 24, 30, 36, 42, 48, 54, 59 } -- minutes the script need to execute
local devicename = 'bmp280'
local filename = '/tmp/temperature.js'
local function tableContains(t, v)
for _, value in pairs(t) do
if v == value then return true end
end
return false
end
commandArray = {}
if tableContains(executeAt, math.floor(os.date('%M'))) then -- check minutes
print(otherdevices_svalues[devicename])
local line = "document.write ('" ..
"Temperature:" .. string.sub(otherdevices_svalues[devicename],1,4).."°C" ..
", Pressure sea level: " .. string.sub(otherdevices_svalues[devicename],13,16).." Hpa" ..
", LastUpdated: " .. otherdevices_lastupdate[devicename] ..
"')"
print(line)
local file = io.open(filename,'w')
file:write(line)
file:close()
end
return commandArray
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- frank666
- Posts: 17
- Joined: Monday 07 December 2020 10:11
- Target OS: Linux
- Domoticz version: 2024.7
- Location: San Marino
Re: Writing temperature til text file
@waaren wonderful !!! it works great! TNX
Domoticz running on Docker,Orange Pi Zero Plus
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Writing temperature til text file
Probably easier to use the otherdevices tables ?
Code: Select all
print('Executing script_time_logForBI')
local executeAt = { 1, 6, 12, 18, 24, 30, 36, 42, 48, 54, 59 } -- minutes the script need to execute
local devicename = 'bmp280'
local filename = '/tmp/temperature.js'
local function tableContains(t, v)
for _, value in pairs(t) do
if v == value then return true end
end
return false
end
commandArray = {}
if tableContains(executeAt, math.floor(os.date('%M'))) then
print(otherdevices_svalues[devicename])
local line = "document.write ('" ..
"Temperature:" .. otherdevices_temperature[devicename] .."°C" ..
", Pressure sea level: " .. otherdevices_barometer[devicename] .." Hpa" ..
", LastUpdated: " .. otherdevices_lastupdate[devicename] ..
"')"
print(line)
local file = io.open(filename,'w')
file:write(line)
file:close()
end
return commandArray
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- frank666
- Posts: 17
- Joined: Monday 07 December 2020 10:11
- Target OS: Linux
- Domoticz version: 2024.7
- Location: San Marino
Re: Writing temperature til text file
@waaren I also tried the method with otherdevices tables, but the value of the temperature contains many decimals after the comma,
I tried putting .. round(otherdevices_temperature[devicename], 2) .. but it does not round.
ps:is it possible to import in a web page the domoticz temperature charts? I will open a new post.
I tried putting .. round(otherdevices_temperature[devicename], 2) .. but it does not round.
ps:is it possible to import in a web page the domoticz temperature charts? I will open a new post.
Domoticz running on Docker,Orange Pi Zero Plus
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Writing temperature til text file
You can round with
Code: Select all
local decimals = 2
"Temperature:" .. math.floor( otherdevices_temperature[devicename] * 10^decimals ) / 10^decimals .."°C" ..
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- frank666
- Posts: 17
- Joined: Monday 07 December 2020 10:11
- Target OS: Linux
- Domoticz version: 2024.7
- Location: San Marino
Re: Writing temperature til text file
nothing. seems not to act on the variable
Domoticz running on Docker,Orange Pi Zero Plus
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Writing temperature til text file
Can you try this ?
Code: Select all
print('Executing script_time_logForBI')
local executeAt = { 1, 6, 12, 18, 24, 30, 36, 42, 48, 54, 59 } -- minutes the script need to execute
local devicename = 'bmp280'
local filename = '/tmp/temperature.js'
local decimals = 2
local function tableContains(t, v)
for _, value in pairs(t) do
if v == value then return true end
end
return false
end
commandArray = {}
if tableContains(executeAt, math.floor(os.date('%M'))) then
print(otherdevices_svalues[devicename])
local line = "document.write ('" ..
"Temperature:" .. math.floor( otherdevices_temperature[devicename] * 10^decimals ) / 10^decimals .. "°C" ..
", Pressure sea level: " .. otherdevices_barometer[devicename] .. " Hpa" ..
", LastUpdated: " .. otherdevices_lastupdate[devicename] ..
"')"
print(line)
local file = io.open(filename,'w')
file:write(line)
file:close()
end
return commandArray
- Spoiler: show
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- frank666
- Posts: 17
- Joined: Monday 07 December 2020 10:11
- Target OS: Linux
- Domoticz version: 2024.7
- Location: San Marino
Re: Writing temperature til text file
works perfectly
Code: Select all
cat /tmp/temperature.js
document.write ('Temperature:1.91°C, Pressure sea level: 1007.0 Hpa, LastUpdated: 2020-12-07 15:43:10')
Domoticz running on Docker,Orange Pi Zero Plus
Who is online
Users browsing this forum: No registered users and 0 guests