stromzaehler
This commit is contained in:
		
							parent
							
								
									bb862ed6ec
								
							
						
					
					
						commit
						43cf6cabea
					
				
					 4 changed files with 109 additions and 0 deletions
				
			
		
							
								
								
									
										37
									
								
								bundles/stromzaehler/files/stromzaehler
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								bundles/stromzaehler/files/stromzaehler
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,37 @@ | |||
| #!/bin/bash | ||||
| 
 | ||||
| #set -x | ||||
| 
 | ||||
| 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 > /tmp/watt | ||||
|       echo $delay $impulse_per_hour $watt | ||||
|       # curl "https://${influxdb_domain}/ping" ${'\\'} | ||||
|       #   -X POST ${'\\'} | ||||
|       #   -H "Authentication: Token ${influxdb_token}" ${'\\'} | ||||
|       #   -d "bucket=${influxdb_bucket}" ${'\\'} | ||||
|       #   -d "ord=${influxdb_org}" ${'\\'} | ||||
|       #   -d "data=powermeter,host=${node_name} watts=$watt" | ||||
|     fi | ||||
|     previous_impulse=$(date --utc +%s%N) | ||||
|   fi | ||||
|   previous_state=$state | ||||
| done | ||||
							
								
								
									
										25
									
								
								bundles/stromzaehler/items.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								bundles/stromzaehler/items.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,25 @@ | |||
| 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'], | ||||
|         }, | ||||
|     }, | ||||
| } | ||||
| 
 | ||||
| svc_systemd = { | ||||
|     'stromzaehler': { | ||||
|         'enabled': False, | ||||
|         'running': False, | ||||
|         'needs': [ | ||||
|             'file:/opt/stromzaehler', | ||||
|         ], | ||||
|     } | ||||
| } | ||||
							
								
								
									
										23
									
								
								bundles/stromzaehler/metadata.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								bundles/stromzaehler/metadata.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,23 @@ | |||
| defaults = { | ||||
|     'apt': { | ||||
|         'packages': { | ||||
|             '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
	
	 mwiegand
						mwiegand