Average 5 readings from a Single device

Hi,

I want to take 5 level (cm) readings which are read every 60 seconds and then get the average of those 5 readings.
Reason I want to do this is I have an ultasonic level device in my garage which checks if my car is present or not. What I am finding is that 1 maybe 2 readings for some reason jump and give an in-accurate reading which then marks my car as present when it is not. I was thinking that if I average the last 5 readings maybe this will be more accurate. I then want to use this average as the present or not present outcome.

Any thing like this available, or anybody doing something similar.

Thanks

If what you use for the ultrasonic sensor is Tasmota, you could use the rules feature of that device and do that type of processing directly on the device. Then just open/close a relay and use the contact sensor child driver.

1 Like

Maybe rather than an average, what about a variable in an RM rule and if you get X consecutive readings you change the status for the car? I'm not a big RM user, but I'm sure it would be possible. There might even be an app that may do something similar.

If you're interested in alternatives, you may also want to read the topic below, if you haven't already.

Hi

I am using an arduino ultrasonic device and the hubduino drivers for HE. I will have a look at RM but I am not to good with it. What I wanted to do is this, currently the garage door opens when I arrive (presence governor) using my phone. With this device I want it to check if my car is already in the garage when I arrive, if so don't open the door.

This is what I suspected, if it is based on the ESP8266 chip you could also use Tasmota. In either the case of Hubduino or Tasmota I would recommend to do the filtering on the device, it would be much faster and wouldn't cause any strain on the hub. If you go the RM route I'm sure someone who actually use it can help out.

Hi @markus you have me wanting to load Tasmota onto the D1 mini, would I use the Hubitat 8.3.1 bin file for the D1 mini? I watched a youtube and they say I must copy the lib folder into the sketches folder from the Tasmota firmware, I only have the bin file? Sorry not sure how to do this?

I think you may need the Tasmota Sensors Hubitat model for that sensor. Previously it was included in the base model, but it isn't anymore. I think Tasmotizer is probably the easiest route to flash it with.

What you do then is just configure the pin you have connected the sensor on and also set an unused pin to have a relay. You can then write rules directly on the device which toggles that relay on and off. On the HE side you can use the Tasmota Universal Switch as Contact Sensor child device drivers. Just change the child device that is created as a Switch to use the Contact Sensor driver instead.

EDIT: I think you may also find that the distance measured by the ultrasonic sensor is not going to "jump" as much with Tasmota, there is a filter already applied on that type of sensor to prevent that. If it still happens, it can be sorted with rules.

Hi markus, okay, flashed the mini with Tasmota , have the ultrasonic connected and reading in cm. What I am not understanding is how to get this to work in HE I will add with your Tasmota device handler, then how do you set this as a presence sensor if the reading is above a certain amount so for example if the distance is more than 150cm then not present, if less then present. Once again thanks for the help so far, really do appreciate it.

Did you also do this? If you did this right you have an on/off button in the Tasmota UI and should get a Child Switch device in HE. Change the driver of the Child Switch device to use the one for Switch as Contact.

Once you have that, it is time to write a rule on the Tasmota device. I'll find some more clear directions on that one for you.

EDIT: Once this is working for you, I'll make a child device driver which will make the switch into a Presence Sensor instead of a Contact sensor. For now, use the Contact Sensor driver.
Give me the output of "Status 0" from the Tasmota Console, please.

1 Like

Okay, yes I do have the toggle switch, and I have added it to HE with the Tasmota device handler, it created a child device with the ultasonic sensor? Should I change this to the Switch as a Contact (where woudl I find this driver, is this one of yours I need to get)

Okay, found your Switch as a contact driver have added that now.

I didn't remember I had support for distance in my multisensor one. This is not the child device you should change driver for though. You should also have one with a switch that can control the fake switch in Tasmota. You might need to press Refresh in the Parent device. The driver to change to (Switch as Contact Sensor) is one of mine, it can be installed using HPM.

EDIT: If you want the Switch as a presence sensor I made a new driver here:

Okay, that was my fault, installed it into HE before I setup the relay, all working now, have changed that to the Switch as a contact sensor driver.

Great, then I just need the output from the console in Tasmota when you type "status 0". Do test that when you turn on/off the relay in Tasmota that the contact sensor updates state.

Yes tested it and if I toggle the switch in the GUI of Tasmota the presence changes in HE,
This is the output of Status0 (should it have a space after status as that spits out a lot more info)

STATUS = {"Status":{"Module":0,"DeviceName":"D1Mini","FriendlyName":["D1 Mini - Universal Parent (192."],"Topic":"tasmota_FB0779","ButtonTopic":"0","Power":1,"PowerOnState":3,"LedState":1,"LedMask":"FFFF","SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0}}

Yes, with that I have everything I need. The space is needed.

Okay here is the output of Status 0
15:40:02 RSL: STATUS = {"Status":{"Module":0,"DeviceName":"D1Mini","FriendlyName":["D1 Mini - Universal Parent (192."],"Topic":"tasmota_FB0779","ButtonTopic":"0","Power":1,"PowerOnState":3,"LedState":1,"LedMask":"FFFF","SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0}}
15:40:02 RSL: STATUS1 = {"StatusPRM":{"Baudrate":115200,"SerialConfig":"8N1","GroupTopic":"tasmotas","OtaUrl":"http://thehackbox.org/tasmota/release/tasmota.bin","RestartReason":"Software/System restart","Uptime":"0T00:28:56","StartupUTC":"2020-07-18T14:11:06","Sleep":50,"CfgHolder":4617,"BootCount":14,"BCResetTime":"2020-07-18T14:11:29","SaveCount":38,"SaveAddress":"F6000"}}
15:40:02 RSL: STATUS2 = {"StatusFWR":{"Version":"8.3.1(sensors-he)","BuildDateTime":"2020-07-04T09:53:17","Boot":31,"Core":"2_7_1","SDK":"2.2.2-dev(38a443e)","Hardware":"ESP8266EX","CR":"437/699"}}
15:40:02 RSL: STATUS3 = {"StatusLOG":{"SerialLog":2,"WebLog":2,"MqttLog":0,"SysLog":0,"LogHost":"","LogPort":514,"SSId":["Sheares",""],"TelePeriod":300,"Resolution":"55C180C0","SetOption":["00008001","280514000100060000005A00000000000000","00000000","80000000"]}}
15:40:03 RSL: STATUS4 = {"StatusMEM":{"ProgramSize":625,"Free":376,"Heap":22,"ProgramFlashSize":1024,"FlashSize":4096,"FlashChipId":"16405E","FlashMode":3,"Features":["00000809","8F8AA787","0415A3A5","B7FFBFCD","01DA9BC4","64367CE7","00000072"],"Drivers":"1,2,3,4,5,6,8,9,10,14,16,17,20,21,24,25,29,34,95","Sensors":"1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,26,28,31,34,37,39,40,42,43,51,52,55,56,58,59,62,64,66,67"}}
15:40:03 RSL: STATUS5 = {"StatusNET":{"Hostname":"tasmota_FB0779-1913","IPAddress":"192.168.0.173","Gateway":"192.168.0.1","Subnetmask":"255.255.255.0","DNSServer":"192.168.0.8","Mac":"98:F4:AB:FB:07:79","Webserver":2,"WifiConfig":4,"WifiPower":17.0}}
15:40:03 RSL: STATUS7 = {"StatusTIM":{"UTC":"2020-07-18T14:40:03","Local":"2020-07-18T15:40:03","StartDST":"2020-03-29T02:00:00","EndDST":"2020-10-25T03:00:00","Timezone":"+01:00","Sunrise":"05:06","Sunset":"20:45"}}
15:40:03 RSL: STATUS10 = {"StatusSNS":{"Time":"2020-07-18T15:40:03","SR04":{"Distance":197.614}}}
15:40:03 RSL: STATUS11 = {"StatusSTS":{"Time":"2020-07-18T15:40:03","Uptime":"0T00:28:57","UptimeSec":1737,"Heap":22,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":29,"MqttCount":0,"POWER":"ON","Wifi":{"AP":1,"SSId":"Sheares","BSSId":"FC:EC:DA:E6:F7:27","Channel":4,"RSSI":74,"Signal":-63,"LinkCount":1,"Downtime":"0T00:00:03"}}}
15:41:17 RSL: STATE = {"Time":"2020-07-18T15:41:17","Uptime":"0T00:30:11","UptimeSec":1811,"Heap":23,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":0,"POWER":"ON","Wifi":{"AP":1,"SSId":"Sheares","BSSId":"FC:EC:DA:E6:F7:27","Channel":4,"RSSI":100,"Signal":-49,"LinkCount":1,"Downtime":"0T00:00:03"}}
15:41:17 RSL: SENSOR = {"Time":"2020-07-18T15:41:17","SR04":{"Distance":197.632}}

Would you prefer a print screen, this looks like gobbledygook :crazy_face:

This is fine :slight_smile: I will write a rule for you. Not 100% sure about the syntax, but should get you close enough.

1 Like

You are an absolute legend and a huge asset to this HE community. I really do appreciate your time and effort you put in.

1 Like