python script messung Druck übergabe fhem

Begonnen von B4unty, 11 Juli 2017, 13:49:54

Vorheriges Thema - Nächstes Thema

B4unty

Hallo zusammen ich habe volgendes python script was mir den gemessenen druck anzeigt. nun würde ich gerne das ergebniss in fhem übergeben um damit eine sicherung der pumpe einzubauen. also wen der druck nicht zwichen 0.2 und 2 bar ist wen die pumpeläuft. schalte die pumpe ab.
import time

import Adafruit_ADS1x15
adc = Adafruit_ADS1x15.ADS1115(address=0x48, busnum=1)

# Gain = 2/3 for reading voltages from 0 to 6.144V.
# See table 3 in ADS1115 datasheet
GAIN = 2/3

# Main loop.
while 1:
    value = [0]
    # Read ADC channel 0
    value[0] = adc.read_adc(0, gain=GAIN)
    # Ratio of 15 bit value to max volts determines volts
    volts = value[0] / 32767.0 * 6.144
    # Tests shows linear relationship between psi & voltage:
    psi = 13 * volts - 5
    # Bar conversion
    bar = psi * 0.0689475729
   
    print("{0:0.3f}V [{1}]".format(volts, value[0]))
    print("\n{0:0.0f} psi {1:0.1f} bar".format(psi, bar))
    print
   
    time.sleep (10)
 

JoWiemann

Anbei ein Vorschlag:


    subprocess.call(['perl', '/opt/fhem/fhem.pl', '7072', 'set <device> <value>'])
    subprocess.call(['perl', '/opt/fhem/fhem.pl', '7072', 'set <device> <reading> <value>'])


Grüße Jörg

PS: Anbei eine Pythonfile, in dem einiges aus Fhem gelesen und geschrieben wird
Jörg Wiemann

Slave: RPi B+ mit 512 MB, COC (868 MHz), CUL V3 (433.92MHz SlowRF); FHEMduino, Aktuelles FHEM

Master: CubieTruck; Debian; Aktuelles FHEM

B4unty

#2
Also so?import time
import subprocess

import Adafruit_ADS1x15
adc = Adafruit_ADS1x15.ADS1115(address=0x48, busnum=1)

# Gain = 2/3 for reading voltages from 0 to 6.144V.
# See table 3 in ADS1115 datasheet
GAIN = 2/3

# Main loop.
while 1:
    value = [0]
    # Read ADC channel 0
    value[0] = adc.read_adc(0, gain=GAIN)
    # Ratio of 15 bit value to max volts determines volts
    volts = value[0] / 32767.0 * 6.144
    # Tests shows linear relationship between psi & voltage:
    psi = 13 * volts - 5
    # Bar conversion
    bar = psi * 0.0689475729
   
    print("{0:0.3f}V [{1}]".format(volts, value[0]))
    print("\n{0:0.0f} psi {1:0.1f} bar".format(psi, bar))
    print
subprocess.call(['perl', '/opt/fhem/fhem.pl', '7072', 'set PumpeDruck <bar>'])
    subprocess.call(['perl', '/opt/fhem/fhem.pl', '7072', 'set PumpeDruck <reading> <bar>'])
   
    time.sleep (10)

das scheint falsch zu sein
Zitatsubprocess.call(['perl', '/opt/fhem/fhem.pl', '7072', 'set <PumpeDruck> <bar>'])
                                                                                   ^
IndentationError: unindent does not match any outer indentation level

JoWiemann

Äh, <> die müssen weg! <> zeigen an, dass ihr ein Wert stehen muss, [] das ein Wert stehen kann.


Gesendet von iPhone mit Tapatalk
Jörg Wiemann

Slave: RPi B+ mit 512 MB, COC (868 MHz), CUL V3 (433.92MHz SlowRF); FHEMduino, Aktuelles FHEM

Master: CubieTruck; Debian; Aktuelles FHEM

B4unty

da schein ich noch was zu brauchen
subprocess.call(['perl', '/opt/fhem/fhem.pl', '7072', 'set PumpeDruck 150'])
    ^
IndentationError: unexpected indent

B4unty

Irgendwie scheine ich nach dem falschen zu suchen 😞

JoWiemann

Sorry, aber ich bin kein Python Freak und wurschtele mich da auch immer nur durch.

Grüße Jörg
Jörg Wiemann

Slave: RPi B+ mit 512 MB, COC (868 MHz), CUL V3 (433.92MHz SlowRF); FHEMduino, Aktuelles FHEM

Master: CubieTruck; Debian; Aktuelles FHEM

JoWiemann

Hast Du das Paket:python-subprocess32 installiert?

Grüße Jörg
Jörg Wiemann

Slave: RPi B+ mit 512 MB, COC (868 MHz), CUL V3 (433.92MHz SlowRF); FHEMduino, Aktuelles FHEM

Master: CubieTruck; Debian; Aktuelles FHEM

B4unty