Compare commits
2 commits
bb862ed6ec
...
bc898c8009
Author | SHA1 | Date | |
---|---|---|---|
![]() |
bc898c8009 | ||
![]() |
43cf6cabea |
4 changed files with 111 additions and 0 deletions
35
bundles/stromzaehler/files/stromzaehler
Normal file
35
bundles/stromzaehler/files/stromzaehler
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# gpiochip number + pin number
|
||||||
|
gpio=$(expr 458 + 3)
|
||||||
|
|
||||||
|
# prepare
|
||||||
|
if ! [[ -e "/sys/class/gpio/gpio$gpio" ]]; then
|
||||||
|
echo $gpio > "/sys/class/gpio/export"
|
||||||
|
fi
|
||||||
|
echo in > "/sys/class/gpio/gpio$gpio/direction"
|
||||||
|
|
||||||
|
# loop
|
||||||
|
previous_state=false
|
||||||
|
while sleep 0.001; do
|
||||||
|
state=$(cat "/sys/class/gpio/gpio$gpio/value")
|
||||||
|
if ! [[ "$state" = "$previous_state" ]] && [[ "$state" = 0 ]]
|
||||||
|
then
|
||||||
|
if ! [ -z $previous_impulse ] # skip first iteration
|
||||||
|
then
|
||||||
|
delay=$(expr $(date --utc +%s%N) - $previous_impulse)
|
||||||
|
impulse_per_hour=$(expr 3600000000000 / $delay)
|
||||||
|
watt=$(expr $impulse_per_hour / $(expr 2000 / 1000))
|
||||||
|
echo "$watt watts"
|
||||||
|
curl "https://${influxdb_domain}/api/v2/write?org=${influxdb_org}&bucket=${influxdb_bucket}&precision=ns" ${'\\'}
|
||||||
|
-X POST ${'\\'}
|
||||||
|
--header "Authorization: Token ${influxdb_token}" ${'\\'}
|
||||||
|
--header "Content-Type: text/plain; charset=utf-8" ${'\\'}
|
||||||
|
--header "Accept: application/json" ${'\\'}
|
||||||
|
--data-binary "powermeter,host=${node_name} watts=$watt" ${'\\'}
|
||||||
|
2&> /dev/null &
|
||||||
|
fi
|
||||||
|
previous_impulse=$(date --utc +%s%N)
|
||||||
|
fi
|
||||||
|
previous_state=$state
|
||||||
|
done
|
28
bundles/stromzaehler/items.py
Normal file
28
bundles/stromzaehler/items.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
influxdb_metadata = repo.get_node(node.metadata.get('stromzaehler/influxdb_node')).metadata.get('influxdb')
|
||||||
|
|
||||||
|
files = {
|
||||||
|
'/opt/stromzaehler': {
|
||||||
|
'content_type': 'mako',
|
||||||
|
'mode': '550',
|
||||||
|
'context': {
|
||||||
|
'node_name': node.name,
|
||||||
|
'influxdb_domain': influxdb_metadata['hostname'],
|
||||||
|
'influxdb_bucket': influxdb_metadata['bucket'],
|
||||||
|
'influxdb_org': influxdb_metadata['org'],
|
||||||
|
'influxdb_token': influxdb_metadata['admin_token'],
|
||||||
|
},
|
||||||
|
'triggers': [
|
||||||
|
'svc_systemd:stromzaehler:restart'
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
svc_systemd = {
|
||||||
|
'stromzaehler': {
|
||||||
|
# 'enabled': False,
|
||||||
|
# 'running': False,
|
||||||
|
'needs': [
|
||||||
|
'file:/opt/stromzaehler',
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}
|
24
bundles/stromzaehler/metadata.py
Normal file
24
bundles/stromzaehler/metadata.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
defaults = {
|
||||||
|
'apt': {
|
||||||
|
'packages': {
|
||||||
|
'curl': {},
|
||||||
|
'gpiod': {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'systemd': {
|
||||||
|
'units': {
|
||||||
|
'stromzaehler.service': {
|
||||||
|
'Unit': {
|
||||||
|
'Description': 'stromzaehler',
|
||||||
|
'After': 'network.target',
|
||||||
|
},
|
||||||
|
'Service': {
|
||||||
|
'ExecStart': '/opt/stromzaehler',
|
||||||
|
},
|
||||||
|
'Install': {
|
||||||
|
'WantedBy': {'multi-user.target'},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
24
nodes/home.stromzaehler.py
Normal file
24
nodes/home.stromzaehler.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
{
|
||||||
|
'hostname': '10.0.0.15',
|
||||||
|
'groups': [
|
||||||
|
'debian-11',
|
||||||
|
'raspberry-pi',
|
||||||
|
'monitored',
|
||||||
|
],
|
||||||
|
'bundles': [
|
||||||
|
'stromzaehler',
|
||||||
|
],
|
||||||
|
'metadata': {
|
||||||
|
'id': 'dd521b8a-dc03-43f5-b29f-068f948ba3b8',
|
||||||
|
'network': {
|
||||||
|
'internal': {
|
||||||
|
'interface': 'eth0',
|
||||||
|
'ipv4': '10.0.0.15/24',
|
||||||
|
'gateway4': '10.0.0.1',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'stromzaehler': {
|
||||||
|
'influxdb_node': 'home.server',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
Loading…
Reference in a new issue