How to get nested values to lovelace card or to custom mqtt sensor
stanogustafik opened this issue · 4 comments
Thank you so much for your RPi-Reporter-MQTT2HA-Daemon. Everything works great with my Raspberry Pi 3B+ also with Dietpi software installed on it.
Only thing I cannot solve is how to get some additional or nested values from MQTT to lovelace card or to create MQTT sensor. Here are the values of main sensor as showing in Developer tools States :
cpu:
bogo_mips: "153.60"
hardware: BCM2835
load_15min_prcnt: 0.5
load_1min_prcnt: 0.5
load_5min_prcnt: 1.2
model: ""
number_cores: 4
serial: 00000000bffacffa
drives:
mnt-store:
device: /dev/sda1
mount_pt: /mnt/store
size_gb: 256
used_prcnt: 10
root:
device: /dev/root
mount_pt: /
size_gb: 128
used_prcnt: 2
fqdn: DietPi.home
fs_free_prcnt: 98
fs_total_gb: 128
fs_used_prcnt: 2
host_name: DietPi
ifaces: e,w,b
last_update: "2023-12-06T08:56:08+01:00"
mem_used_prcnt: 16
memory:
free_mb: 803
free_swap: 1089
size_mb: 960
size_swap: 1089
networking:
eth0:
IP: 192.168.1.114
mac: b8:27:eb:fa:cf:fa
rx_data: 4
tx_data: 9
report_interval: 1
reporter: ISP-RPi-mqtt-daemon v1.8.5
reporter_releases: v1.8.5,v1.7.2,v1.7.3,v1.7.4,v1.8.3,v1.8.4
rpi_model: RPi 3 Model B+r1.3
temp_cpu_c: 49.4
temp_gpu_c: 49.4
temperature_c: 49.4
throttle:
- throttled = 0x0
- Not throttled
timestamp: "2023-12-06T10:07:58+01:00"
up_time: " 1:12"
up_time_secs: 4320
ux_release: bookworm
ux_updates: 0
ux_version: 6.1.21-v8+
device_class: timestamp
icon: mdi:raspberry-pi
friendly_name: Dietpi - Stav aktualizovaný
Specially I need to get value of "drives/mnt-store/used_prcnt"
I tried everything - to use lovelace attribute card - to create custom MQTT sensor... unsuccesfully...
this is what MQTT explorer shows from rpimonitor:
{
"info": {
"timestamp": "2023-12-06T10:25:17+01:00",
"timestamp": "2023-12-06T10:26:18+01:00",
"rpi_model": "RPi 3 Model B+r1.3",
"ifaces": "e,w,b",
"host_name": "DietPi",
"fqdn": "DietPi.home",
"ux_release": "bookworm",
"ux_version": "6.1.21-v8+",
"ux_updates": 0,
"up_time": " 1:29",
"up_time_secs": 5340,
"up_time": " 1:30",
"up_time_secs": 5400,
"last_update": "2023-12-06T08:56:08+01:00",
"fs_total_gb": 128,
"fs_free_prcnt": 98,
"fs_used_prcnt": 2,
"networking": {
"eth0": {
"IP": "192.168.1.114",
"mac": "b8:27:eb:fa:cf:fa",
"rx_data": 4,
"tx_data": 7
}
},
"drives": {
"root": {
"size_gb": 128,
"used_prcnt": 2,
"device": "/dev/root",
"mount_pt": "/"
},
"mnt-store": {
"size_gb": 256,
"used_prcnt": 10,
"device": "/dev/sda1",
"mount_pt": "/mnt/store"
}
},
"memory": {
"size_mb": 960,
"free_mb": 803,
"size_swap": 1089,
"free_swap": 1089
},
"mem_used_prcnt": 16,
"cpu": {
"hardware": "BCM2835",
"model": "",
"number_cores": 4,
"bogo_mips": "153.60",
"serial": "00000000bffacffa",
"load_1min_prcnt": 0,
"load_5min_prcnt": 0,
"load_15min_prcnt": 0
},
"throttle": [
"throttled = 0x0",
"Not throttled"
],
"temperature_c": 49.4,
"temp_gpu_c": 49.4,
"temperature_c": 48.9,
"temp_gpu_c": 48.9,
"temp_cpu_c": 49.4,
"reporter": "ISP-RPi-mqtt-daemon v1.8.5",
"reporter_releases": "v1.8.5,v1.7.2,v1.7.3,v1.7.4,v1.8.3,v1.8.4",
"report_interval": 1
}
}
Please, do you have any suggestions or some example of yaml which would work? Thank you so much!
https://github.com/ironsheep/lovelace-rpi-monitor-card#example-monitoring-of-specific-attributes
Any use?
I tried a few things, but I never could split the sub attributes.
Might be worth a question with the HA forum.
The card is great... but no chance to add any additional values... and with mqqt sensor programming in Home Assistant I just need a little advice...
SOLUTION:
the answer is that you can read nested attributes from the monitor sensor (its primary value is time in seconds or minutes from last sensor update) - there are nested values... no need to read directly mqtt, they are already read in this sensor. Then the template sensors in configuration.yaml are:
template:
- sensor:
name: "Storage used percentage"
state_class: measurement
unit_of_measurement: '%'
state: "{{ state_attr('sensor.dietpi_rpi_monitor', 'drives' )['mnt-store']['used_prcnt'] }}"
- sensor:
name: "Raspberry IP address"
state: "{{ state_attr('sensor.dietpi_rpi_monitor', 'networking' )['eth0']['IP'] }}"
- sensor:
name: "Raspberry monitor interval"
unit_of_measurement: "minutes"
state: "{{ state_attr('sensor.dietpi_rpi_monitor', 'report_interval' ) }}"
It would be much easier, but when they are "hyphens" or "dashes" used in the attributes´ IDs, you have to use this syntax with ["..."]["..."]
I hope this could help you, maybe it could be part of wiki or readme file... bye...