Spanish Total.js
Italiano
Documentazione Per agenti IA
Indice

Show a live value on a panel

Read the last value of a published sensor and show it on a panel every minute with a small script.

.md Sito web

Questa pagina non è ancora tradotta. Stai leggendo l’originale.

In questa pagina

This recipe shows the temperature of a park on a display at its entrance. A small script on any computer reads the published sensor and sends the panel new HTML.

Prepare the platform

  1. Publish the sensor: open the device, select the cog icon of the sensor and Publish to API endpoint. Copy the address shown under the sensor.
  2. Create a panel with Width 480 and Height 240. See Panels.
  3. Select ... on the panel, then Copy Flow URL address.
  4. Open the address from Copy panel URL address on the display.

The script

Save this as panel.sh, put in the two addresses you copied and run it every minute, for example from cron:

#!/bin/sh
SENSOR='https://iot.example.com/opendata/sensors/?id=<device id><sensor id>'
PANEL='https://iot.example.com/panels/<panel id>/?token=<token>'

VALUE=$(curl -s "$SENSOR" | sed -E 's/.*"value":([0-9.-]+).*/\1/')

curl -s -X POST "$PANEL" -H 'Content-Type: application/json' \
  -d "{\"html\":\"<div style='font-family:Arial;text-align:center;padding:40px'><div style='font-size:20px'>City park</div><div style='font-size:72px;font-weight:bold'>$VALUE °C</div></div>\"}"

Each run answers {"success":true}, and the display shows the new value at once, without reloading.

A Flow can do the same: read the address of the sensor, build the HTML and post it to the Flow URL address of the panel.

Fatto in Europa