diff --git a/README.md b/README.md index 88703b14eecb1ad357bff49c992cdebfba2d4299..5492f95bbdbcfc4225b3a9ae6b18a710d444728a 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ Sensors - LM75 i2c temperature sensor (`lm75`) - DHT11 DHT22 AM2302 temperature/humidity sensor (`dht22`) - BH1750 light level sensor (`bh1750`) +- DS18S20, DS1822, DS18B20, DS1825, DS28EA00, MAX31850K one-wire temperature sensors: (`ds18b`) Installation ------------ @@ -148,6 +149,17 @@ sensor_inputs: interval: 10 digits: 2 +sensor_modules: + - name: ds18b22 + module: ds18b + type: DS18S20 + address: 000803702e49 + +sensor_inputs: + - name: ds18b22 + module: ds18b22 + interval: 60 + digits: 2 ``` #### SSL/TLS diff --git a/config.example.yml b/config.example.yml index 9fcc900498bebe1dbfe076fd52ad4d105d86ec2b..156bf83b9cb3ba304b6bac0a5bd61a15667820fb 100644 --- a/config.example.yml +++ b/config.example.yml @@ -24,6 +24,11 @@ sensor_modules: i2c_bus_num: 1 chip_addr: 0x48 + - name: ds18b22 + module: ds18b + type: DS18S20 + address: 000803702e49 + digital_inputs: - name: button module: raspberrypi @@ -57,7 +62,12 @@ digital_outputs: off_payload: "OFF" sensor_inputs: - - name: temperature + - name: temp_lm75 module: lm75 interval: 15 - digits: 4 \ No newline at end of file + digits: 4 + + - name: temp_dsb18 + module: ds18b22 + interval: 10 + digits: 2 diff --git a/pi_mqtt_gpio/modules/ds18b.py b/pi_mqtt_gpio/modules/ds18b.py new file mode 100644 index 0000000000000000000000000000000000000000..5a47f53a47f46a43e3862679919d6f3da33dea4d --- /dev/null +++ b/pi_mqtt_gpio/modules/ds18b.py @@ -0,0 +1,40 @@ +from pi_mqtt_gpio.modules import GenericSensor + +REQUIREMENTS = ("w1thermsensor",) +ALLOWED_TYPES = ["DS18S20", "DS1822", "DS18B20", "DS1825", "DS28EA00", "MAX31850K"] +CONFIG_SCHEMA = { + "address": dict(type="string", required=True, empty=False), + "type": dict( + type="string", required=True, empty=False, allowed=ALLOWED_TYPES + list(map(str.lower, ALLOWED_TYPES)) + ), +} + +class Sensor(GenericSensor): + """ + Implementation of Sensor class for the one wire temperature sensors. DS18B etc. + """ + + def __init__(self, config): + from w1thermsensor import W1ThermSensor + + sensor_config_type = config["type"] + + #get the sensor type mapping + self.sensor_type = None + for w1_sensor_type, w1_sensor_name in W1ThermSensor.TYPE_NAMES.items(): + if w1_sensor_name.lower() == sensor_config_type.lower(): + self.sensor_type = w1_sensor_type + + # initialization failed + if self.sensor_type is None: + raise Exception("Supported sensor types: " + str(W1ThermSensor.TYPE_NAMES.values())) + + self.sensor = W1ThermSensor(self.sensor_type, config["address"].lower()) + + def setup_sensor(self, config): + return True # nothing to do here + + def get_value(self, config): + """get the temperature value from the sensor""" + temperature = self.sensor.get_temperature() + return temperature