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.
Esta página aún no está traducida. Estás leyendo el original.
En esta página
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
- 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.
- Create a panel with Width
480and Height240. See Panels. - Select ... on the panel, then Copy Flow URL address.
- 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.