Database polling component

Just started with HA (and Python) and am attempting to connect my existing home automation system which I wrote myself. My existing system (written in c#) takes sensor data from Tinkerforge components and puts the data into a table in an MS SQL Server database.

HA does not have a Tinkerforge component so I considered writing my own but decided it would be easier and quicker for now for me to just make a component to poll the database for sensor data. Perhaps later I’ll write a ‘proper’ Tinkerforge component but really I just wanted to get on using HA with my existing sensor network.

Onto my issue - I have got the component written and I can now get temperature/humidity/etc data to my dashboard. I’ve moved onto the motion detectors and got it working but the updates are too slow.
Looking at SQL Profiler I can see the database is being polled every 30 seconds. Fine for temperature data, not fine for motion sensors (or button pushes). How can I speed up the polling rate to say once per second? I’ve hunted everywhere and the only thing I can set is should_poll = True. The api isn’t showing me a way to set this speed. I’ve found util.throttle but this seems to be about slowing it down not speeding it up.

Perhaps I should writing my own loop somehow and then pushing the updates to HA? I can see in other components stuff related to looping and async calls but really I’d just like a bare bones example of the best way to do this as I don’t know where I should put this loop. So far I have two files - one under sensor and one under binary_sensor but no core overall platform file. I perform my database poll in the update method of the sensor class.

Overall perhaps a database polling component could be added (perhaps by me if this works). Would welcome a bit of feedback on the best approach here!

There is a “scan_interval” config parameter that you can set on any polling component to override the 30 second interval- however the best way to get immediate feedback would be for your existing system to do a call in. The mqtt protocol immediately comes to mind there, as there are pre-created mqtt switches/lights/you name it. I bet there is a c# library for mqtt, and hass has a built in server too.

Thanks for your reply. I think MQTT is the way too - especially having found Tinkerforge have their own MQTT proxy service.