2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants;
15 import java.util.HashMap;
19 * The {@link SensorEnum} lists all available digitalSTROM sensor types.
21 * @author Michael Ochel - Initial contribution
22 * @author Matthias Siegele - Initial contribution
23 * @see <a href="http://developer.digitalstrom.org/Architecture/ds-basics.pdf">ds-basics.pdf, Table 40: Sensor Types
24 * from ds-basic.pdf from 19.08.2015</a>
26 public enum SensorEnum {
28 * | Sensor Type | Description | Unit | Min | 12 Bit Max | 12 Bit Resolution |
29 * -----------------------------------------------------------------------------------------------------------------
30 * -------------------------------------------------------------
31 * | 4 | Active power | Watts (W) | 0 | 4095 | 1 |
32 * | 5 | Output current | Ampere (mA) | 0 | 4095 | 1 |
33 * | 6 | Electric meter | Kilowatt hours (kWh) | 0 | 40,95 | 0,01 |
34 * | 9 | Temperature indoors | Kelvin (K) | 230 | 332,375 | 0,25 | (not correct)
35 * | 10 | Temperature outdoors | Kelvin (K) | 230 | 332,375 | 0,25 | (not correct)
36 * | 11 | Brightness indoors | Lux (Lx) | 1 | 131446,795 | logarithmic: lx = 10 * (x/800), x = 800 * log(lx) |
37 * | 12 | Brightness outdoors | Lux (Lx) | 1 | 131446,795 | logarithmic: lx = 10 * (x/800), x = 800 * log(lx) |
38 * | 13 | Relative humidity indoors | Percent (%) | 0 | 102,375 | 0,025 |
39 * | 14 | Relative humidity outdoors | Percent (%) | 0 | 102,375 | 0,025 |
40 * | 15 | Air pressure | Pascal (hPa) | 200 | 1223,75 | 0,25 |
41 * | 18 | Wind speed | Meters per second (m/s) | 0 | 102,375 | 0,025 |
42 * | 19 | Wind direction | degrees | 0 | 511,875 | 0,54 |
43 * | 20 | Precipitation | Milliliter per square meter (ml/m2) | 0 | 102,375 | 0,025 |
44 * | 21 | Carbon Dioxide | Parts per million (ppm) | 1 | 131446,795 | logarithmic: ppm = 10 * (x/800), x = 800 * log
46 * | 25 | Sound pressure level | Decibel (dB) | 0 | 255,938 | 0,25/4 |
47 * | 50 | Room temperature set point | Kelvin (K) | 230 | 332,375 | 0,025 | (not correct)
48 * | 51 | Room temperature control variable | Percent (%) | 0 | 102,375 | 0,025 |
49 * | 64 | Output current (H) | Ampere (mA) | 0 | 16380 | 4 |
50 * | 65 | Power consumption | Volt-Ampere (VA) | 0 | 4095 | 1 |
52 * Note: Point 20 precipitation, mm/m2 doesn't exist as unit, so it's liter or milliliter per square meter (ml/m2 or
54 * otherwise it's only mm what is the same as l/m2)
57 ACTIVE_POWER((short) 4, "watt", "W", 0, 4095, 1, "%d"),
58 OUTPUT_CURRENT((short) 5, "ampere", "mA", 0, 4095, 1, "%d"),
59 ELECTRIC_METER((short) 6, "kilowatt_hours", "kWh", 0, (float) 40.95, (float) 0.01, "%.3f"),
60 TEMPERATURE_INDOORS((short) 9, "kelvin", "K", 230, (float) 332.375, (float) 0.25, "%.2f"),
61 TEMPERATURE_OUTDOORS((short) 10, "kelvin", "K", 230, (float) 332.375, (float) 0.25, "%.2f"),
62 BRIGHTNESS_INDOORS((short) 11, "lux", "Lx", 1, (float) 131446.795, 800, "%.3f"),
63 BRIGHTNESS_OUTDOORS((short) 12, "lux", "Lx", 1, (float) 131446.795, 800, "%.3f"),
64 RELATIVE_HUMIDITY_INDOORS((short) 13, "percent", "%", 0, (float) 102.375, (float) 0.025, "%.2f"),
65 RELATIVE_HUMIDITY_OUTDOORS((short) 14, "percent", "%", 0, (float) 102.375, (float) 0.025, "%.2f"),
66 AIR_PRESSURE((short) 15, "pascal", "hPa", 0, (float) 1223.75, (float) 0.25, "%.2f"),
67 WIND_SPEED((short) 18, "meters_per_second", "m/s", 0, (float) 102.375, (float) 0.025, "%.2f"),
68 WIND_DIRECTION((short) 19, "degrees", "°", 0, (float) 511.875, (float) 0.54, "%.2f"),
69 PRECIPITATION((short) 20, "millimeter_per_square_meter", "mm/m2", 0, (float) 102.375, (float) 0.025, "%.3f"),
70 CARBON_DIOXIDE((short) 21, "parts_per_million", "ppm", 1, (float) 131446.795, 800, "%.3f"),
71 SOUND_PRESSURE_LEVEL((short) 25, "decibel", "dB", 0, (float) 255.938, (float) 0.0625, "%.2f"),
72 ROOM_TEMPERATURE_SET_POINT((short) 50, "kelvin", "K", 230, (float) 332.375, (float) 0.025, "%.2f"),
73 ROOM_TEMPERATURE_CONTROL_VARIABLE((short) 51, "kelvin", "K", 230, (float) 332.375, (float) 0.25, "%.2f"),
74 OUTPUT_CURRENT_H((short) 64, "ampere", "mA", 0, 16380, 4, "%d"),
75 POWER_CONSUMPTION((short) 65, "volt_ampere", "VA", 0, 4095, 1, "%d");
77 private final Short sensorType;
78 private final String unit;
79 private final String unitShortcut;
80 private final String pattern;
81 private final Integer min;
82 private final Float max;
83 private final Float resolution;
85 static final Map<Short, SensorEnum> SENSOR_ENUMS = new HashMap<>();
87 SensorEnum(Short sensorType, String unit, String unitShortcut, int min, float max, float resolution,
89 this.sensorType = sensorType;
91 this.unitShortcut = unitShortcut;
94 this.resolution = resolution;
95 this.pattern = plattern;
99 for (SensorEnum sensor : SensorEnum.values()) {
100 SENSOR_ENUMS.put(sensor.getSensorType(), sensor);
105 * Returns true, if the given typeIndex contains in digitalSTROM, otherwise false.
107 * @param typeIndex to be checked
108 * @return true, if contains otherwise false
110 public static boolean containsSensor(Short typeIndex) {
111 return SENSOR_ENUMS.keySet().contains(typeIndex);
115 * Return true, if the given {@link SensorEnum} is a climate sensor, otherwise false.
117 * @param sensorType to check
118 * @return true, if {@link SensorEnum} is climate sensor, otherwise false.
120 public static boolean isClimateSensor(SensorEnum sensorType) {
121 if (sensorType != null) {
122 switch (sensorType) {
123 case TEMPERATURE_INDOORS:
124 case TEMPERATURE_OUTDOORS:
125 case BRIGHTNESS_INDOORS:
126 case BRIGHTNESS_OUTDOORS:
127 case RELATIVE_HUMIDITY_INDOORS:
128 case RELATIVE_HUMIDITY_OUTDOORS:
134 case SOUND_PRESSURE_LEVEL:
135 case ROOM_TEMPERATURE_SET_POINT:
136 case ROOM_TEMPERATURE_CONTROL_VARIABLE:
146 * Return true, if the given {@link SensorEnum} is a power sensor, otherwise false.<br>
147 * <b>Power sensors are:</b><br>
148 * - {@link #ACTIVE_POWER}<br>
149 * - {@link #OUTPUT_CURRENT}<br>
150 * - {@link #ELECTRIC_METER}<br>
151 * - {@link #OUTPUT_CURRENT_H}<br>
152 * - {@link #POWER_CONSUMPTION}
154 * @param sensorType to check
155 * @return true, if {@link SensorEnum} is power sensor, otherwise false.
157 public static boolean isPowerSensor(SensorEnum sensorType) {
158 if (sensorType != null) {
159 switch (sensorType) {
163 case OUTPUT_CURRENT_H:
164 case POWER_CONSUMPTION:
174 * Returns the {@link SensorEnum} for the given typeIndex, otherwise null.
176 * @param typeIndex of the {@link SensorEnum}
177 * @return SensorEnum or null
179 public static SensorEnum getSensor(Short typeIndex) {
180 return SENSOR_ENUMS.get(typeIndex);
184 * Returns the typeIndex of this {@link SensorEnum} object.
188 public Short getSensorType() {
189 return this.sensorType;
193 * Returns the unit of this {@link SensorEnum} object.
197 public String getUnit() {
202 * Returns the unit shortcut of this {@link SensorEnum} object.
204 * @return unit shortcut
206 public String getUnitShortcut() {
207 return this.unitShortcut;
211 * Returns the pattern of this {@link SensorEnum} object for display.
215 public String getPattern() {
220 * Returns the minimum sensor value.
222 * @return the min value
224 public Integer getMin() {
229 * Returns the maximum sensor value.
231 * @return the max value
233 public Float getMax() {
238 * Returns resolution for this sensor to get the float value of the dS-value (e.g. dSsensorValue * getResolution()).
242 * If the resolution is 800, than you have to calculate "10 * (dSsensorValue/800)".
244 * @return the resolution
246 public Float getResolution() {