Hi,
As far as I can see, if you want to do some calculations using time the resolution is 1 second.
Is there a way to get better resolution? e.g. hundreds of second?
KR
-Bart
time resolution
Moderator: leecollings
-
- Posts: 395
- Joined: Sunday 03 July 2016 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2024.7
- Location: Netherlands
- Contact:
time resolution
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
- waltervl
- Posts: 5886
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: time resolution
For calculations in dzVents you can also use milliseconds, see https://www.domoticz.com/wiki/DzVents:_ ... nd_methods
eg compare(time), millisecondsAgo
I suppose in LUA this also can be done.
eg compare(time), millisecondsAgo
I suppose in LUA this also can be done.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: time resolution
I would not know how to do it in classic Lua but in dzVents you can work with milliseconds
Code: Select all
return
{
on =
{
timer =
{
'every minute'
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'currentTime',
},
execute = function(dz)
dz.log(_G.globalvariables.currentTime,dz.LOG_DEBUG)
dz.log(dz.time.milliseconds,dz.LOG_DEBUG)
end
}
Code: Select all
2021-01-14 00:41:00.322 Status: dzVents: Info: currentTime: ------ Start internal script: Script #1:, trigger: "every minute"
2021-01-14 00:41:00.324 Status: dzVents: Debug: currentTime: 2021-01-14 00:41:00.278
2021-01-14 00:41:00.324 Status: dzVents: Debug: currentTime: 278
2021-01-14 00:41:00.326 Status: dzVents: Info: currentTime: ------ Finished Script #1
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
-
- Posts: 395
- Joined: Sunday 03 July 2016 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2024.7
- Location: Netherlands
- Contact:
Re: time resolution
Hi,
This is the code which I expect that has now and then failures due to timing
------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------
I'm sorry as I don't know how to put the code in a "code window"
Remarks are in dutch language.
Brief explanation:
I have a lighting for the stairs which is controlled by a so called bi-stable relay. That means that you give a short pulse to the relay coil to change the status of the relay contacts.
And another pulse for changing the status again.
I have two movement-sensor (433Mhz) (Bew1 and Bew2) once there is one of them activated the light (Lamp-trap) goes on.
But sometimes it seems that (due to timing ?) the function of the relay has been inverted so once the sensor is activated the light goes off and after the requested "on "time the relay goes on iso off.
Any idea this is timing problem or something others?
TIA
-Bart
This is the code which I expect that has now and then failures due to timing
------------------------------------------------------------------------------------------------------------------------
Code: Select all
-- ~/domoticz/scripts/lua/script_device_pirs.lua
-- Each of the motion sensors in Domoticz follow this name convention:
-- PIRxyzSwitchName or PIRxyzGroupName
-- x speicifies when the PIR controls - a=all day, n=nighttime, d=daytime, s=Dummy switch set in Domoticz which
-- has to be on for the PIR to operate - Dummy-SwitchName or Dummy-GroupName
-- custom-timers can be set by creating a timed dummy switch in Domoticz
-- y specifies what the PIR is controlling - r = room (single Domoticz) switch and g = group
-- z specifies how long the ligth will stay on for in minutes, so z =5 turns the switch or the group on for 5 minutes
-- N.B. be carefully as currently there is little error checking so wrongly named PIRs in Domoticz may cause an error
-- N.B. one wrongly named PIR may stop the script, check log for any issues
function timedifference(s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
--
commandArray = {}
tc = next(devicechanged)
if (tc == 'Bew1-trap') or (tc == 'Bew2-trap') then
if timeofday['Daytime'] then
-- overdag het traplicht niet aan doen
return
end
-- tijdstip waarop lamp is aangezet
ccc = uservariables['TraplichtAanTijdstip']
-- aantal verstreken seconden sinds lamp is aangezet
x=timedifference(ccc)
-- als er weer een schakelcommando komt binnen 60 seconden na het eerste commando: doe verder niets
if x < 60 then
return
end
f=tostring(os.date('%Y-%m-%d %H:%M:%S'))
commandArray ['Variable:TraplichtAanTijdstip']= (f)
-- licht werkt met bistabiel relais ; bij 1e commando gaat licht aan; bij 2e uit
commandArray['Lamp-Trap'] = 'On REPEAT 2 INTERVAL 60' -- command will be repeated 2 times with 60 seconds interval
end
return commandArray
I'm sorry as I don't know how to put the code in a "code window"
Remarks are in dutch language.
Brief explanation:
I have a lighting for the stairs which is controlled by a so called bi-stable relay. That means that you give a short pulse to the relay coil to change the status of the relay contacts.
And another pulse for changing the status again.
I have two movement-sensor (433Mhz) (Bew1 and Bew2) once there is one of them activated the light (Lamp-trap) goes on.
But sometimes it seems that (due to timing ?) the function of the relay has been inverted so once the sensor is activated the light goes off and after the requested "on "time the relay goes on iso off.
Any idea this is timing problem or something others?
TIA
-Bart
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: time resolution
click on the marked button and paste your code between the inserted tags.
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
Who is online
Users browsing this forum: No registered users and 1 guest