I hope for your patience if it's a stupid question

Moderator: leecollings
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
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
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
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
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
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
You can round with
Code: Select all
local decimals = 2
"Temperature:" .. math.floor( otherdevices_temperature[devicename] * 10^decimals ) / 10^decimals .."°C" ..
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
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')
Users browsing this forum: No registered users and 1 guest