Skip to main content leehalls.net

Posts on Python

  1. Home Assistant

    A long time ago i setup & wrote my own home monitoring system using wireless temperature sensors and a current clamp across the incoming feed to the house for electricity monitoring (take a look at the projects section for flask socketio) Using it i was able to educate the step-son about taking 90 minute long showers without contributing to the bills1 i then moved house leaving the current clamp hardware in place duh then what with getting the house sorted, travelling for work and subsequent long hours on my return i never set it up again besides the long shower taker had buggered off saving me loads of cash :-)

  2. Orgmode without emacs

    Is it possible to use org without emacs?

    For most people it would seem from various internet searches that what keeps them using emacs is orgmode. It is certainly true for me that 75% of my emacs usage is purely org based with the rest being python (yes i know its not good python), tramp and the odd text edit though i still find SublimeText an easier option for somethings. Though to answer the question posed at the start the answer was always no, yes we have the various mobile options such as orgzly, orgro, metanote, plainorg but some of these have limited functionality and personal opinion ahead … I would say are more an extension of the desktop org allowing you to view your data and capture basic info and for the desktop you needed emacs but

  3. Python export for specific tagged headlines & files in org documents

    [2022-11-11 Fri] renamed this article because in my mind “parser” indicates something more than this is. This is just a way to read an org file and extract headings identifed with a specific tag and only the linked files for that heading/tag not all the files i have stored in the data directory.

  4. Realtime data plotting

    Following on from my earlier post trying to use smoothiecharts with flask-socketio for realtime data i managed to get an alternative with a pillion onboardwith a pillion onboardworking this time using charts https://www.chartjs.org/ Using this i am now able to generate random data (in lieu of external input values) and have them graphed in realtime on a line chart created using the api. The main part of the flask-python element consists of the data creation routine

  5. Smoothiecharts, python, flask & socketio

    OK a long time ago i got gauges working with flask-socketio for a home monitoring project and that’s all documented here in a github repo: Gauges, flask-socketio

    Fast forward to now and i have a use for realtime line graphs, searching i came across the smoothiecharts api, and it looked perfect for my needs. Initially i followed some leads and ended up with the python program launched using a bash wrapper and followed by commandline websocket ie

  6. VL53L1X & a Raspberry Pico

    [2021-09-03 Fri] update: as you’ll see here (reddit link) someone has ported the CircuitPytohn driver to MicroPython for some reason i never found it when i started this but his github driver can be found here: https://github.com/truckershitch/micropython-vl53l0x

    I’ve had an idea for checking the height of a equipment during its movement for some time now and thought the small form factor of the pico + the VL53L1X sensor would be an ideal candidate. So after much searching and trial/error it seemed it wasnt possible until i stumbled across a few threads in the micro-python forum and the openmv github site and i now have a working setup;

  7. Querying the SQL

    This is taken from a previous website post but the problem still remains, my home monitoring system has 4 zone with a wireless temperature sensor in each. They all wake up individually on a periodic basis and each time one sensor outputs data the main program writes an entry into the SQL database for all zones so only the sensor currently transmitting has new data and the previous readings from the other sensors are stored with the new.

  8. Pandas SQL and pain

    I’ve left the home monitoring system alone for a few years, its just sat quietly in the garage collating data into an SQL database, the only changes made recently were to move everything onto a Pi4 and add an additional camera into the motioneye system running on the same Pi. So as its a slow day i decided now was the time to update it or rather start work on it. One thing i wanted to do was re-instigate the live readings and an auto graph element and for this i needed to extract data - simple i got my old code somewhere …. somewhere … maybe.

  9. outlook events for orgmode

    If like me you spend all your working life in MS products and yet you still want to or do rely on orgmode to give you some semblance of sanity, then this might help. Its not a bidirectional synchronisation and i only wanted the appointments for today to show. It queries Outlook for any confirmed appointments in the calendar and then outputs a single orgmode file in my main org folder which is automatically added to the agenda. The following code originally taken from https://sukhbinder.wordpress.com/2020/04/08/get-outlook-entries-with-python-3/ then gutted and adapted for my needs queries MS Outlook for the events in the calendar. I’ve restricted it for one day but changing the variable num_days can output more if you wanted.

  10. Beginning Outlook email analysis

    [2020-06-24 Wed 22:36] This was originally titled “Outlook email analysis” but on reflection it sounded to presumptious for what is actually shown hence the new “beginning” addition/

    Its been a productive week and this morning i finally got around to trying my hand at using python to conduct some simple Outlook inbox analysis. I’ve wanted for a long time to have more data visualisation and so another journey begins. The following piece of code is simple and needs improvement but what it does is to connect to the outlook mailbox, and loop through all emails to provide a count of emails received against a persons name for today and it creates an org table output

  11. dirty python for quick link creation

    As the sub-heading to this site suggests this maybe a place to find poor python! I was updating my photography galleries and in doing so creating ox-hugo clickable image links so that the main page shows the thumbnail and a click brings up the main image. Anyway its a pain to go C-c C-l for each and every file so i cobbled together a dirty and quick python script to trawl a directory and create a text file with the necesary ox-hugo links for clickable images.

  12. comparing data

    After getting bokeh to graph data I started trying to compare years/months against each other eg June 2019 vs 2018 but this did not quite go to plan especially as i had forgotten that despite dragelec running for almost 5yrs the SQL recording only started in Aug 2018…

    There is another issue; the way the data is recorded; i store values everytime a signal is output from one of the sensors this means when interrogating the data i can have a different number of values per day so a straight forward export of data does not work.

  13. a year of data

    Xmas is a pretty dead time for me, so i finally got round to programming something to export the data from the sql db and then more importantly graph it.

    I have struggled for ages trying to use matplotlib and was close to giving up then i stumbled across bokeh and magic happened, a gift at xmas time :smile: in short a few simple lines of code and i now have a scalable graph of data that works on this site as well as the dashboard monitor. Below is an image of the output;

  14. PIR controlled pi display

    Dragelec did at one time update via socketio to a flask based website showing temperatures, electricity usage and local weather but rather than leaving the display on all the time i added a PIR to turn it on/off whenever a presence was detected, the following is the complete code;

    python code snippet start

  15. adding epoch time to database

    Not pretty but it works…

    After a power cut had stopped the data recording on my home monitor I decided to follow up on my earlier post of storing the date in epoch format instead of just a date/time string by converting the existing db to add an epoch column, what follows is not pretty & probably not something anyone should follow. It’s cobbled together from my beginners knowledge and of course internet searches…

  16. Learning SQL and some poor python

    Since converting to storing the data in sqlite form i’ve been learning how to extract specific sections of data so i can then learn how to graph it and ultimately serve it on the home dashboard and during these experiments i can see my decode routine is not quite as efficient as i originally thought as it lets through non-numeric data so lets look at the sql extraction code and then the decode issue;

  17. home monitor conversion

    I finally have some ‘free’ time so i upgraded a few things on the pi server but not without issues,

    From jessie to stretch - network drive

    For some reason the old command for mounting a network drive on the pi which worked on jessie did not work under stretch. I kept getting a host is down fault yet it was clearly not. The line i had in fstab before was;

  18. shortening the code

    The module i wrote for decoding the sensor data stream bugged me it was too repetitive with multiple if statements ie;

    python code snippet start

  19. prep for moving methods

    Sorting out everything for the transition to hugo i find that the wordpress plugins had created multiple copies of images in all different sizes whereas I only need the main size plus the 150x150 as a thumbnail and rather than rename by hand every filen from filename-150x150.jpg to filename-thumb.jpg i wrote the following quick and dirty python to do for it for me.

    python code snippet start