Programming your personal weather chart

This blog explains how to program your individual personal weather chart, to predict when it will rain or snow, down to the minute, at your exact location.

Weather charts are fantastic. You’ll need them almost every day, they are tiny and filled with hopefully trust able information. But to arrange several information in one small size of dashboard is quite a challenge. Here is what I do:

  1. Request a free weather service hourly to get actual weather data.
  2. Store the weather data in a local database
  3. Display it in a individual weather chart, to get all the needed information in only one glance.

What do I need?

  • A PC, Mac, Raspberry Pi or any kind of hardware able to run InfluxDB and Grafana
  • Coordinates of the place (Latitude and Longitude) your weather chart is representing
  • Some time and fun when trying out new things

InfluxDB Installation and Setup

Follow the installation instructions. Start by adding the InfluxData repository, install it and start the InfluxDB service.

After a successful installation, let’s start InfluxDB and create a database and users with their rights:

$ influx
Connected to http://localhost:8086 version 1.2.4
InfluxDB shell version: 1.2.4
> CREATE DATABASE weather_db
> CREATE USER admin WITH PASSWORD 'INFLUXDB_ADMIN_PASSWORD' WITH ALL PRIVILEGES
> CREATE USER darksky WITH PASSWORD 'INFLUXDB_DARKSKY_PASSWORD'
> CREATE USER grafana WITH PASSWORD 'INFLUXDB_GRAFANA_PASSWORD'
> GRANT ALL ON weather_db TO darksky
> GRANT READ ON weather_db TO grafana
> exit

Enable authentication in the [http] section of the configuration file /etc/influxdb/influxdb.conf:

[http]
enabled = true bind-address = ":8086" # change to a specific interface if needed 
auth-enabled = true # will enforce authentication
...

Note: When starting influx next time you will ask for authentication. Use:
influx -username admin -password INFLUXDB_ADMIN_PASSWORD -host localhost

Grafana Installation and Setup

To install Grafana, follow their excellent installation instructions. After successful installation of Grafana, open the dashboard at http://grafana_host:3000. (Or if you’re installed on the same machine: http://localhost:3000)
First login with the default credentials: admin:admin.

Connecting Grafana to InfluxDB

Logged in to the Grafana dashboard, go to “Data Sources” and create a new source pointing to your InfluxDB database, providing the credentials you chose when setting up the InfluxDB database.

Getting the data

Hourly forecast data is provided by darksky.net. Once you have signed up for an developer API key, you’re able to receive up to 1000 requests a day for free.
This would allow a refresh every 1.5 minutes, without having to pay. Hey, this is really a very nice deal!

So time to grab the data:

Installing and setup the script

The following script does the job, you just need to configure it to your setup.

It requests the dark sky API using your provided key and stores the data within your Influxdb databases. It’s capable of re-run itself in a variable period using cron as a build in function. All you need to do is install, configure the config file and run it.

Here is how you clone the repository and configure it to your setup:

Clone repository git clone https://github.com/SvenSommer/darksky2influxdb

Node and npm

Node and npm are required. See https://docs.npmjs.com/getting-started/installing-node.

Test your version by

node -v
npm -v

Get the latest npm version with npm install npm@latest -g

Installing

  1. Enter cloned directory: cd darksky2influxdb and install dependencies npm install
  2. Configure config/default.yml file

Here is an example of default.yml

general:
  debug: true
  cron: '*/15 * * * *'
darksky:
  key: abcdefghiklmnopqrstuvwxyz1234567
  units: auto
  longitude: -123.41670367098749
  latitude: 47.20296790272209
influxdb:
  host: 192.168.188.2
  database: weather
  username: darkskyimport_user
  password: supersecretpassword!?
Option Description
debug Enables Debug mode and provides additional informations

Type: booleon
Possible values: true,false

cron Programm is repating itself in a given period

Type: string
Possible values: '*/15 * * * *' – every 15 minutes,
'' – running only once

darksky – key get your darksky key here https://darksky.net/dev/register

Type: string
Possible values: abcdefghiklmnopqrstuvwxyz1234567

darksky – units Return weather conditions in the requested units. See https://darksky.net/dev/docs/forecast

Type: string
Possible values: auto,ca,uk2,us,si

darksky – longitude and latitude Coordinates of forecast location (in decimal degrees).

Type: float
Possible values: latitude: 47.20296790272209 and longitude:-123.41670367098749

influxdb – host Server your influxdb is running

Type: string
Possible values: localhost , 192.168.188.2

influxdb – database Name of your Database the forecast data is stored.

Type: string
Possible values: weather , forecast

influxdb – username User with writing privileges on the database
influxdb – password Password of user with writing privileges on the database

Running the Import

Start the import with node importForecast.js If you have given a valid cron interval in the configfile the program will repeat the import automatically.

Create your own weather chart in Grafana

Perfect. Now everything is setup and the data is available, the real fun starts!

Time to build you personal weather chart. When you want to start from the scratch I can hardly recommend you the Grafana Graph Panel documentation. Also interesting:

If you’d like you can also use my dashboard. It’s available on the official Grafana website or stored in your cloned directory  grafana\Weather - Forecast-Dashboard.json.


To import it to Grafana simply use their function.

Display it on my mirror!

To display the generated chart on a MagicMirror you can use a module MMM-GrafanaChart.

Help needed? Tell me!

How did everything worked out? Did I miss something? Or if you got stuck, I’ll try my best to help you out!

Do you want to share your weather chart? Just tell me with a comment!

Building a mobile projector box – The Idea

The Idea

To watch movies from time to time on a canvas is the most comfortable position, I decided to place the projector right under my bed. In case it’s not used I would just slip it under the bed frame.

An easy solution was found by using a cardboard box, but  after some days a more orderly and safer solution was needed. So I decided to build a nice casing, which collects the cables and protects the projector.

It stated out the following features were useful:

  • low height of the case, capable to be stored under the bed (max height 21 cm)
  • two areas with the case (top and bottom), to hide the cables under to projector
  • adjustable horizontal angle of the projector
  • dust proof storage, if not in use
  • optional: sockets for power and Ethernet

See here the creation of the housing with several interfaces…

Building a big MagicMirror with metal frame – The summary, part list and prices

This blog shows the costs, used parts and summarizes the main challenges I experienced when building my smart mirror.

The Summary

When I first run into the MagicMirror project I was convinced this was something I wanted to build on my own.  Without the amazing work and the easy to use framework by Michael Teeuw, this wouldn’t any possible to archive. And this was real fun!

What did it cost?

It total I spend exactly 737,70 € on this project. Much more than I was expecting in the beginning. As already told, most expensive was the TV Screen. But see yourself…

Items Object Model Price
1 Frame custom 100,00 €
1 Mirror custom 110,00 €
1 Screen Samsung UE32J6250SU 32 Full HD Smart TV Wifi Black 354,89 €
1 Mount Hama Fix Ultraslim TV Wall Mount Medium Black 14,99 €
1 RaspberryPi3 Raspberry PI 3 Model B A1.2GHz 64-bit quad-core ARMv8 CPU, 1GB RAM 37,93 €
1 RaspiCase SB Components Raspberry Pi 3 Transparent Case 6,49 €
1 Camera Raspberry Pi camera module NoIR V2 36,90 €
1 Power Supply Rydges EU 5V 3A Micro USB Power Supply 9,99 €
1 Short HDMI cable 0,2m SunshineTronic High Speed HDMI cable with ethernet 6,90 €
40 Infrared LEDs Infrared OSRAM LEDs SFH 485 15,00 €
40 LED reflector 5mm Reflector 5mm 21,21 €
2  Power socket Euro8 9,50 €
1 Power cable white Euro8 Maxima Trade Netzkabel 8,90 €
1 Wires, Screws, woodbars several 5,00 €
Total 737,70 

How long did it take?

It’s hard to say how much time I had spent only on the hardware. I started to dive in the code very early. Maybe 60 to 80 hours including researches regarding the setup and hardware.

What did I learn?

As already told I underestimated the price. But the real challenge in this project was to improve the pictures made with the camera, behind the mirror glass.
Several prototypes of the IR spotlights where built, I had to spend several hours of adjusting parameters and retaking sample pictures for the face recognition module to get it work properly.

After a few month, the number and of modules I’d like use on the mirror started raised. So did the requirements on CPU and memory resources. It turned out the Raspberry Pi 3 quickly reaches its limits, when using modules for face or speech recognition or when displaying a rotating globe. So right now, I’m already thinking about how to rebuild the inner parts to get a board with more power.

What’s next?

 

The possibilities of the Magic Mirror are immense. Now I have this cool piece of data provider right in my hall it’s time to make this a impressive info board. Therefore several modules are easily to add to the open source software framework. Several developers made some amazing software. So did I.
If you’re interested, check out my developed modules for the Magic Mirror.

 

 

Building a big MagicMirror with metal frame – The Assembling

The Assembling

1Time to put everything together. Or with other words let’s say: ‘Grab the duct tape, we’re building a magic mirror’.

 

First a little soldering was needed, to power up the TV screen without using the normal power cable for space reasons.

 

At the bottom of the TV screen a black cardboard prevent any light coming through the mirror. So for person standing right in front of the mirror, also the lower part just looks like a normal mirror.

Behind the cardboard the TV Speakers were taped to provide a nice sound if needed.

 

The Power were already installed and the mirror fits as expected.

The wooden bars which are fixing the frame and mirror to the TV Screen are screwed to the frame.

A proper mount its holding everything tight.

Final installation hanging save on the mount.

Building a Magic mirror – The Summary

Building a big MagicMirror with metal frame – The Camera

The Camera

One of the first modules for the magicmirror framework I had to try myself, was the face-recognition module by paviro. After experimenting some time with the software I was fully convinced. The Mirror needed a camera.

For keeping the ‘magic’ in the mirror, It’s was not an option to mount the camera outside the frame. A grave and not so easy decision as stated out during the further tests.

The mirrors final location is in the windowless doorway. Most of the time no natural lighting helps the camera to make sharp and contrast shots. Maybe an IR version of the raspi camera module could do this tough job? Yes it can, but of course …. it needs infrared light.

Light – even infrared of course – get partially reflected by the two way mirror. Surprise.
So to get the same brightness for a camera behind the mirror you need more like 60 % ‘more’ light than camera outside would need.

But obviously every light emitted by a lamp behind the mirror suffers from the same effect in brightness.

This wasn’t unsolvable, but as I was totally convinced everything had to find its place within the frame it was a tough lesson I had to learn.

With a thin mirror as planned – and a frame already ordered – there was no way integrating a custom infrared spotlight within the mirror. So I decided to try my luck with infrared LED. And hey, why not reflect the light, which was reflected by the mirror again.

So first attempts were made using aluminium foil as ‘re-reflector’. Better but far away from a good image in a near dark environment.

Finally I decided to maximize the number of LEDs with an overall voltage consumption of nearly 12V by two matrices of 3 X 6 spots around the camera. Each LED has a reflector itself to focus in the forward direction.

As the camera is mounted on top of the screen, lights and camera are positioned in an angle of 45° to capture the face of the person viewing in the mirror.

Very helpful for positioning and lights in this position was a acryl mirror behind the led, with an right angled outside part.

The camera itself is connected to the raspberry Pi and was mounted in the wooden bar which is fixing the frame on the monitor.

Finally was able to receive bright pictures which were usable for recognize persons behind the mirror.
Time to start the real fun part: The Assembling

Building a big MagicMirror with metal frame – The Frame

The Frame

With the decision regarding screen  and mirror  taken final dimensions were clear and the fun with constructing a frame could begin. To get a thin product with a solid and industrial look I wanted to use a bent enclosure out of sheet metal.

With the kind help of my flatmate, who owns a hardware prototype company, we were able to design a nice prototype.

The results of the construction process were provided to a nearby metal factory. The design drawing is available for download.


The construction as Solidworks® Part is also available online on Onshape.

After waiting more than five very looong weeks, the frame was finally crafted and made me another 100€ poorer. Man, this was getting way more expensive than first calculated.
But every bad taste vanished when the parts were together for the very first time.

As the TV screen is mounted right to the wall, the frame should ‘sit’ on the screen, holding the glass of the mirror itself. To fix the frame properly to the screen, we first planned to use individual metal blocks on each edge of the screen and tighten them with two screws.

Small spoiler: In the end I decided to use two wooden bars on the top and the bottom of the mirror to fix the frame. There were much more easy to customize and gave an additional vertical stability to the frame.

 

On the top and the button of the frame a place for a power socket was planned. The speakers of the TV screen were easily to ease and found their new place on the button of the frame, able to play through several oval openings.

Soft tape from a ‘hook and loop tape’ is used on the inner side of the frame prevent the monitor screen from feared scratches.

 

Time to put every piece to its final destination – The Assembling

Building a big MagicMirror with metal frame – The Mirror

The Mirror

The “magic” of this project is made by a semi-transparent mirror. When one side of the mirror is brighter than the other it behaves like a window. Otherwise it’s a regular mirror.

To give the glass more stability and to avoid the risk of cutting myself, I found it worth investing in polished edges.

To find a One-way mirror I decided to contact about ten nearby glazier. Only a few responded. Finally I decided to go with a 6mm thick piece by 41 cm x 103 cm for around 75€. If you are looking for a good reseller in Berlin, Germany I can totally recommend this place.

Time to put everything into a frame…

Building a big MagicMirror with metal frame – The Screen

The Screen

Finding the right monitor or HDTV

To get the exact size of the mirror-glass and frame a decision for the monitor was needed. The pc monitor I was looking for was:

  • About 27″ to get a width from 41 cm in portrait orientation
  • As thin as possible
  • Power and video connector needed to be mounted sideways, to get the whole mirror as thin as possible
  • A minimum resolution from 1080p

After some time hanging around in the bigger electronic shops I found some nice models but had to realise I underestimated the prices for pc monitors.

So I started to compare bigger and cheaper smart tv screens. Here is what I’ve learned.

The most important difference between pc monitors and HDTV screens is pixel density, which means the number of pixels placed into one square inch. A 15.6-inch laptop screen has the same number of pixels as the 32-inch HDTV screen, but the laptop has a much higher pixel density (141.21ppi) than does the HDTV (68.84ppi). The laptop’s screen will appear clearer, sharper, and more detailed than the HDTV’s screen when viewed from the same distance. The importance of pixel density decreases with viewing distance; that’s why the iPhone’s “Retina” screen has a density of 326ppi, while the MacBook Pro’s “Retina” screen has a density of just 227ppi.

So a decision had to be made. The bigger the better? Or a more detailed and sharp view?

 

I decided to give it a try and ordered a brand new Samsung UE32J6250. This 32″ HDTV has a diagonal ratio by 15:9 which provided me some extra height of a total of 70 cm by a width of still 42 cm (in portrait orientation).

Preparing the screen

To get the whole mirror as thin as possible I removed the casing. It’s a bit thrilling to open a new and never used TV, but hey, living on the edge …

By the way, you better be careful with the sharp edges of the frame, I just cut myself several times while removing the spindly plastic case.

While tearing everything apart it showed had some nice advantages. The speakers were easy to detach and would find a new place in the lowest part of the frame. Also the control knob and the IR receiver weren’t glued to the frame and could easily find a new position.

Next step – The Mirror

 

Building a big MagicMirror with metal frame – The Idea & Concept

The Idea

Just like the cool guys in there space ships, I was fascinated by the idea of a centralised info board in our home, to show personal info for your day or actual states of our smart home.

Then I stumpled about the Magic Mirror project from Michael Teeuw and was convinced. Without a doubt a Magic Mirror was needed in our home.

I started to figure out what was needed: an observation mirror, a thin monitor, a Raspberry Pi, some casing and lots of spare time.

The Concept

Concept of the magic mirror

There was already a big mirror in our hallway. The measurements by 41 cm x 103 cm seemed to by reasonable for a full body check before leaving the house.

The thickness of the whole mirror is caused by the monitor, the glass and the frame. To keep it as thin as possible at decided to try a metal frame which would hold the inner parts.

Monitors at a display size by 27″ have a height from 41 cm and a width from 55 cm. Rotated by 90 degrees this would fit, but would not cover to whole space behind the mirror. But hey, left spaces could be used for other tools like speakers or a camera above and beneath the monitor.

So lets start with the Screen