rules calculate time difference in milliseconds
Moderators: grovkillen, Stuntteam, TD-er
rules calculate time difference in milliseconds
is there a way to save the time in milliseconds so i can compare it with an earlier variable
i want to calculate the time it takes between 2 events but need it in millisecond accuracy(eg 1 second is not accurate enough)
so basically i want
on trigger 1
save seconds and milliseconds in variable A
on trigger 2
save seconds and milliseconds in variable B
substract B from A to get the exact time between 2 events
if %sysmillisec% would have existed i could use thast one but i only see %syssec%
also total time can not be saved with millisecond accuracy
i want to calculate the time it takes between 2 events but need it in millisecond accuracy(eg 1 second is not accurate enough)
so basically i want
on trigger 1
save seconds and milliseconds in variable A
on trigger 2
save seconds and milliseconds in variable B
substract B from A to get the exact time between 2 events
if %sysmillisec% would have existed i could use thast one but i only see %syssec%
also total time can not be saved with millisecond accuracy
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: rules calculate time difference in milliseconds
Same here, only seconds officially.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
Re: rules calculate time difference in milliseconds
Well if it is for debugging purposes, then you could have a look at the logs, where things are displayed in msec resolution.
Currently we don't have something to be used in rules that can handle msec resolution.
Also the rules parsing itself may take some time, so the timestamp of the sample should be recorded and made available somehow, as it is rather useless to determine a timestamp in msec in the rules.
The fluctuation in rules execution is in the order of a second and not msec.
Some plugins or controllers may block execution of other code for some time.
It would be great if all of these blocking code parts don't block for > 100 msec, but as you may see in the timing stats page, there are quite a few parts that may take > 100 msec (highlighted in that page)
These blocks also have effect on the rules execution.
Currently we don't have something to be used in rules that can handle msec resolution.
Also the rules parsing itself may take some time, so the timestamp of the sample should be recorded and made available somehow, as it is rather useless to determine a timestamp in msec in the rules.
The fluctuation in rules execution is in the order of a second and not msec.
Some plugins or controllers may block execution of other code for some time.
It would be great if all of these blocking code parts don't block for > 100 msec, but as you may see in the timing stats page, there are quite a few parts that may take > 100 msec (highlighted in that page)
These blocks also have effect on the rules execution.
Re: rules calculate time difference in milliseconds
ok clear.
i am doning the timing now in domoticz and calcultate the time difference between 2 SendtoHTTP calls
i notice however that there is a 1 second delay between the same calls
the first time the SendtoHTTP is 1 second different from the second
it fluctuates on a regular base
it loops until the counter has reached 4 and then does a SendHTTP to domoticz yo update the watermeter by 4 liters
call 1 17 seconds
call 2 18 seconds
call 3 17 seconds
call 4 18 seconds
below is the code
what could be causing this 1 second delay
Watermeter(device 1) updates every second
Liters(device 3), every 60 seconds
i am doning the timing now in domoticz and calcultate the time difference between 2 SendtoHTTP calls
i notice however that there is a 1 second delay between the same calls
the first time the SendtoHTTP is 1 second different from the second
it fluctuates on a regular base
it loops until the counter has reached 4 and then does a SendHTTP to domoticz yo update the watermeter by 4 liters
call 1 17 seconds
call 2 18 seconds
call 3 17 seconds
call 4 18 seconds
below is the code
what could be causing this 1 second delay
Watermeter(device 1) updates every second
Liters(device 3), every 60 seconds
On System#Boot do // When the ESP boots, do
TaskValueSet 3,1,0 // TaskValueSet TASKnr,VARnr,Value, Reset the Liters counter to 0
EndOn
On Watermeter#Count do // When Pulse is detected
if [Watermeter#Count] > 0
TaskValueSet 3,1,[Liters#Counter]+1 // Set the Pulse to the Liters dummy sensor
endif
if [Liters#Counter] = 4 // send every 4 liters to domoticz for better resolution
SendToHTTP 192.168.1.50,8084,/json.htm?type=command¶m=udevice&idx=337&nvalue=0&svalue=4
TaskValueSet 3,1,0
endif
EndOn
Re: rules calculate time difference in milliseconds
My guess would be the call to sending data to the controller.what could be causing this 1 second delay
Please have a look at the controller settings.
And timing on the receiving end will not give you any usable indication of the time difference between samples.
There are way too many unknowns affecting the latency on the receiving end.
Re: rules calculate time difference in milliseconds
ok clear.
i will change the rules so i do the calculation inside the ESP(on a 1 second base)
i can then see if the flow readings are more consistent
UPDATE******
flow is more consistent but on a 1 liter resolution of course
Also used a second variable to reset the flow after 60 seconds if water usage is zero.
watermeter gets updated instantly
flowmeter every 60 seconds
i will change the rules so i do the calculation inside the ESP(on a 1 second base)
i can then see if the flow readings are more consistent
UPDATE******
flow is more consistent but on a 1 liter resolution of course
Also used a second variable to reset the flow after 60 seconds if water usage is zero.
watermeter gets updated instantly
flowmeter every 60 seconds
Code: Select all
//------------ INITIAL RELEASE
On System#Boot do
TaskValueSet 3,1,0
TaskValueSet 3,2,0
TimerSet,1,60
EndOn
On Watermeter#Count do
if [Watermeter#Count] > 0
TaskValueSet 3,1,[Liters#Counter]+1
SendToHTTP 192.168.1.50,8084,/json.htm?type=command¶m=udevice&idx=337&nvalue=0&svalue=1
endif
EndOn
On Rules#Timer=1 do
if [Liters#Counter] > 0 or [Liters#Previous] > 0
SendToHTTP 192.168.1.50,8084,/json.htm?type=command¶m=udevice&idx=338&nvalue=0&svalue=[Liters#Counter]
TaskValueSet 3,2,[Liters#Counter]
TaskValueSet 3,1,0
endif
TimerSet,1,60
Endon
Re: rules calculate time difference in milliseconds
i noticed that the time variable from the pulse counter is actually showing the time between pulses in ms.
i am now taking that number to calculate the flow in liters
e.g. 60000/ Time= flow
seems to work very accurate and also the number correspond with the flow i expect.
i am now taking that number to calculate the flow in liters
e.g. 60000/ Time= flow
seems to work very accurate and also the number correspond with the flow i expect.
Re: rules calculate time difference in milliseconds
Can you give the relevant part of your rules?
I am not entirely sure I understand where the time value comes from.
I am not entirely sure I understand where the time value comes from.
Re: rules calculate time difference in milliseconds
sure,
here is the code
works really well and i do not need to count pulses in a 60 second interval but know instantly what the flow is
here is the code
the time part is coming form a pulse counter where it is the Time part (pulsecounter which sents Delta/Total/Time)On Watermeter#Count do // When Pulse is detected
if [Watermeter#Count] > 0
SendToHTTP 192.168.1.50,8084,/json.htm?type=command¶m=udevice&idx=337&nvalue=0&svalue=1
TaskValueSet 3,3,60000/[Watermeter#Time]
SendToHTTP 192.168.1.50,8084,/json.htm?type=command¶m=udevice&idx=338&nvalue=0&svalue=[Liters#Flow]
endif
works really well and i do not need to count pulses in a 60 second interval but know instantly what the flow is
Re: rules calculate time difference in milliseconds
Ah OK, that's nice indeed and very useful. (as in we should add it to the documentation as an example )
Re: rules calculate time difference in milliseconds
indeed we should
here is the complete script(i left some stuff in so that it is backwards compatible in case i want to start counting pulses again every 60 seconds
here is the complete script(i left some stuff in so that it is backwards compatible in case i want to start counting pulses again every 60 seconds
interval of the pulse counter is 1 secondOn System#Boot do // When the ESP boots, do
TaskValueSet 3,1,0 // TaskValueSet TASKnr,VARnr,Value, Reset the Liters counter to 0
TaskValueSet 3,2,0 // TaskValueSet TASKnr,VARnr,Value, Reset the PreviousLiters counter to 0
TaskValueSet 3,3,0 // TaskValueSet TASKnr,VARnr,Value, Reset the Flow counter to 0
TaskValueSet 3,4,0 // TaskValueSet TASKnr,VARnr,Value, Reset the PreviousFlow counter to 0
TimerSet,1,30 // Set Timer 1 for the next event in 30 seconds
EndOn
On Watermeter#Count do // When Pulse is detected
if [Watermeter#Count] > 0
SendToHTTP 192.168.1.50,8084,/json.htm?type=command¶m=udevice&idx=337&nvalue=0&svalue=1
TaskValueSet 3,3,60000/[Watermeter#Time]
SendToHTTP 192.168.1.50,8084,/json.htm?type=command¶m=udevice&idx=338&nvalue=0&svalue=[Liters#Flow]
endif
EndOn
On Rules#Timer=1 do // When Timer 1 expires, do
if [Liters#Flow] > 0 or [Liters#PreviousFlow] > 0 // Only send value if amount of Liters > 0
SendToHTTP 192.168.1.50,8084,/json.htm?type=command¶m=udevice&idx=338&nvalue=0&svalue=[Liters#Flow]
TaskValueSet 3,4,[Liters#Flow] // set flow to previous counter
TaskValueSet 3,3,0
endif
TimerSet,1,30 // Set Timer 1 for the next event in 30 seconds
Endon
Who is online
Users browsing this forum: No registered users and 28 guests