All topics

Sensor Data

NAS Reborn reads the instruments of the iPhone or iPad itself: the air pressure, the power and battery, movement and the noise in the room. It keeps their history and hands them to template sites as ordinary template values.

What the device itself measures

The phone has these built in. You turn on the ones you want in the picker of the Sensor dashboard example.

They work the same on every version of iOS and iPadOS that NAS Reborn runs on, from iOS 15, so an iPhone 6s makes as good a sensor board as a new phone. NAS Reborn reads only the device's own sensors, not the accessories in Apple Home.

Reading them in a page

The readings arrive as device.sensors:

{{ device.sensors.pressure }} hPa, {{ device.sensors.noise }} dB
{% if device.sensors.power == "battery" %}On battery at {{ device.sensors.battery }}%{% endif %}
Last moved at {{ device.sensors.tamper | date: "%H:%M" }}

Each reading also has _updated_at after its name, such as device.sensors.pressure_updated_at, for when it last changed. A page is rendered again when a value it printed has moved, and pages that read no readings are not affected.

History and charts

Readings are recorded on the device, minute by minute for 48 hours and then as hourly figures going back around 400 days. A page reaches them through _history after the reading's name, with points every ten minutes for the last 48 hours, hourly statistics for the last 14 days, daily statistics for the long one and events for power flips and movement, which is enough to draw a chart from the device alone.

{% assign series = device.sensors.pressure_history %}

The Sensor Dashboard example

On an iPhone or iPad, the quickest start is Add example → Sensor dashboard… on the Content tab. Pick the sensors you want and it writes a working site with a tile per reading with meters and charts, a readings.json endpoint, and tiles that update themselves over a live stream rather than reloading the page. Everything it writes is ordinary template source you can edit.

A Mac does not offer the Sensor dashboard. It has no barometer or movement sensor, so a dashboard would have little to show.

To choose a dashboard's tiles from a browser, make an editor for it. Its Sensors page lists the sensors this device has, which any page can read as device.builtin_sensors.

Sensitive readings stay off the open web

The screen of a public folder with its Serve sensitive data switch

Some readings say whether anyone is home. The noise level from the microphone is one, since hours of quiet mean an empty house. Air pressure, power, battery and movement do not and are treated as ordinary values.

On a public folder, a page reading a sensitive value is served only once you turn on Serve sensitive data on that folder's screen. Until then the page is replaced by a short refusal that keeps the reading and its value to itself.

The Sensor Dashboard example is created protected, so it works for your household straight away and faces the internet only when you decide it should.

The microphone is measured while a page in a folder served to browsers read the noise level the last time it was rendered, whether or not anyone is viewing it, and it stands aside while a camera feed with audio is streaming. The store holds a number in dB once a second, and the audio itself is discarded.