Skip to content

Commit

Permalink
Merge pull request #101 from astrandb/MoistSoil
Browse files Browse the repository at this point in the history
Add Moist/Soil transmitter
  • Loading branch information
astrandb authored Jan 7, 2024
2 parents c3b5171 + 53d12b3 commit aca52f0
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 6 deletions.
59 changes: 56 additions & 3 deletions custom_components/weatherlink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
49,
50,
51,
# 55,
76,
77,
78,
Expand Down Expand Up @@ -302,8 +301,8 @@ def _preprocess(indata: str):

if (
sensor["sensor_type"] in SENSOR_TYPE_VUE_AND_VANTAGE_PRO
and sensor["data_structure_type"] == 23
):
or sensor["sensor_type"] in [55]
) and sensor["data_structure_type"] == 23:
tx_id = sensor["data"][0]["tx_id"]
outdata.setdefault(tx_id, {})
outdata[tx_id][DataKey.SENSOR_TYPE] = sensor["sensor_type"]
Expand Down Expand Up @@ -372,6 +371,60 @@ def _preprocess(indata: str):
]
outdata[tx_id][DataKey.UV_INDEX] = sensor["data"][0]["uv_index"]

if sensor["sensor_type"] == 56 and sensor["data_structure_type"] == 12:
tx_id = sensor["data"][0]["tx_id"]
outdata.setdefault(tx_id, {})
outdata[tx_id][DataKey.SENSOR_TYPE] = sensor["sensor_type"]
outdata[tx_id][DataKey.DATA_STRUCTURE] = sensor[
"data_structure_type"
]
outdata[tx_id][DataKey.TEMP_1] = sensor["data"][0]["temp_1"]
outdata[tx_id][DataKey.TEMP_2] = sensor["data"][0]["temp_2"]
outdata[tx_id][DataKey.TEMP_3] = sensor["data"][0]["temp_3"]
outdata[tx_id][DataKey.TEMP_4] = sensor["data"][0]["temp_4"]
outdata[tx_id][DataKey.MOIST_SOIL_1] = sensor["data"][0][
"moist_soil_1"
]
outdata[tx_id][DataKey.MOIST_SOIL_2] = sensor["data"][0][
"moist_soil_2"
]
outdata[tx_id][DataKey.MOIST_SOIL_3] = sensor["data"][0][
"moist_soil_3"
]
outdata[tx_id][DataKey.MOIST_SOIL_4] = sensor["data"][0][
"moist_soil_4"
]
outdata[tx_id][DataKey.WET_LEAF_1] = sensor["data"][0]["wet_leaf_1"]
outdata[tx_id][DataKey.WET_LEAF_2] = sensor["data"][0]["wet_leaf_2"]
if sensor["sensor_type"] == 56 and sensor["data_structure_type"] == 25:
tx_id = sensor["data"][0]["tx_id"]
outdata.setdefault(tx_id, {})
outdata[tx_id][DataKey.SENSOR_TYPE] = sensor["sensor_type"]
outdata[tx_id][DataKey.DATA_STRUCTURE] = sensor[
"data_structure_type"
]
outdata[tx_id][DataKey.TEMP_1] = sensor["data"][0]["temp_1"]
outdata[tx_id][DataKey.TEMP_2] = sensor["data"][0]["temp_2"]
outdata[tx_id][DataKey.TEMP_3] = sensor["data"][0]["temp_3"]
outdata[tx_id][DataKey.TEMP_4] = sensor["data"][0]["temp_4"]
outdata[tx_id][DataKey.MOIST_SOIL_1] = sensor["data"][0][
"moist_soil_1"
]
outdata[tx_id][DataKey.MOIST_SOIL_2] = sensor["data"][0][
"moist_soil_2"
]
outdata[tx_id][DataKey.MOIST_SOIL_3] = sensor["data"][0][
"moist_soil_3"
]
outdata[tx_id][DataKey.MOIST_SOIL_4] = sensor["data"][0][
"moist_soil_4"
]
outdata[tx_id][DataKey.WET_LEAF_1] = sensor["data"][0]["wet_leaf_1"]
outdata[tx_id][DataKey.WET_LEAF_2] = sensor["data"][0]["wet_leaf_2"]
outdata[tx_id][DataKey.TRANS_BATTERY_FLAG] = sensor["data"][0][
"trans_battery_flag"
]

if sensor["sensor_type"] == 365 and sensor["data_structure_type"] == 21:
tx_id = primary_tx_id
outdata[tx_id][DataKey.TEMP_IN] = sensor["data"][0]["temp_in"]
Expand Down
12 changes: 9 additions & 3 deletions custom_components/weatherlink/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class WLBinarySensorDescription(BinarySensorEntityDescription):
translation_key="trans_battery",
entity_category=EntityCategory.DIAGNOSTIC,
exclude_api_ver=(ApiVersion.API_V1,),
exclude_data_structure=(2,),
aux_sensors=(55,),
exclude_data_structure=(2, 12),
aux_sensors=(55, 56),
),
)

Expand Down Expand Up @@ -78,7 +78,13 @@ async def async_setup_entry(
for sensor in hass.data[DOMAIN][config_entry.entry_id]["sensors_metadata"]:
if sensor["tx_id"] is not None and sensor["tx_id"] != primary_tx_id:
for description in SENSOR_TYPES:
if sensor["sensor_type"] in description.aux_sensors:
if (
sensor["sensor_type"] in description.aux_sensors
and coordinator.data[sensor["tx_id"]].get(
DataKey.DATA_STRUCTURE
)
not in description.exclude_data_structure
):
aux_entities.append(
WLSensor(
coordinator,
Expand Down
11 changes: 11 additions & 0 deletions custom_components/weatherlink/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class DataKey(StrEnum):
HEAT_INDEX = "heat_index"
HUM_IN = "hum_in"
HUM_OUT = "hum_out"
MOIST_SOIL_1 = "moist_soil_1"
MOIST_SOIL_2 = "moist_soil_2"
MOIST_SOIL_3 = "moist_soil_3"
MOIST_SOIL_4 = "moist_soil_4"
RAIN_DAY = "rain_day"
RAIN_MONTH = "rain_month"
RAIN_RATE = "rain_rate"
Expand All @@ -44,15 +48,22 @@ class DataKey(StrEnum):
SOLAR_PANEL_VOLT = "solar_panel_volt"
SOLAR_RADIATION = "solar_radiation"
SUPERCAP_VOLT = "supercap_volt"
TEMP_1 = "temp_1"
TEMP_2 = "temp_2"
TEMP_3 = "temp_3"
TEMP_4 = "temp_4"
TEMP_IN = "temp_in"
TEMP_OUT = "temp_out"
TIMESTAMP = "timestamp"
THW_INDEX = "thw_index"
THSW_INDEX = "thsw_index"
TRANS_BATTERY_FLAG = "trans_battery_flag"
TRANS_BATTERY_VOLT = "trans_battery_volt"
UUID = "station_id_uuid"
UV_INDEX = "uv_index"
WET_BULB = "wet_bulb"
WET_LEAF_1 = "wet_leaf_1"
WET_LEAF_2 = "wet_leaf_2"
WIND_CHILL = "wind_chill"
WIND_DIR = "wind_dir"
WIND_MPH = "wind_mph"
Expand Down
154 changes: 154 additions & 0 deletions custom_components/weatherlink/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ class WLSensorDescription(SensorEntityDescription):
exclude_data_structure=(
2,
10,
12,
25,
),
),
WLSensorDescription(
Expand All @@ -328,6 +330,8 @@ class WLSensorDescription(SensorEntityDescription):
exclude_data_structure=(
2,
10,
12,
25,
),
),
WLSensorDescription(
Expand All @@ -343,8 +347,158 @@ class WLSensorDescription(SensorEntityDescription):
exclude_data_structure=(
2,
10,
12,
25,
),
),
WLSensorDescription(
key="MoistSoil1",
tag=DataKey.MOIST_SOIL_1,
translation_key="moist_soil_1",
icon="mdi:watering-can-outline",
suggested_display_precision=0,
native_unit_of_measurement=UnitOfPressure.CBAR,
state_class=SensorStateClass.MEASUREMENT,
exclude_api_ver=(ApiVersion.API_V1,),
exclude_data_structure=(
2,
10,
),
aux_sensors=(56,),
),
WLSensorDescription(
key="MoistSoil2",
tag=DataKey.MOIST_SOIL_2,
translation_key="moist_soil_2",
icon="mdi:watering-can-outline",
suggested_display_precision=0,
native_unit_of_measurement=UnitOfPressure.CBAR,
state_class=SensorStateClass.MEASUREMENT,
exclude_api_ver=(ApiVersion.API_V1,),
exclude_data_structure=(
2,
10,
),
aux_sensors=(56,),
),
WLSensorDescription(
key="MoistSoil3",
tag=DataKey.MOIST_SOIL_3,
translation_key="moist_soil_3",
icon="mdi:watering-can-outline",
suggested_display_precision=0,
native_unit_of_measurement=UnitOfPressure.CBAR,
state_class=SensorStateClass.MEASUREMENT,
exclude_api_ver=(ApiVersion.API_V1,),
exclude_data_structure=(
2,
10,
),
aux_sensors=(56,),
),
WLSensorDescription(
key="MoistSoil4",
tag=DataKey.MOIST_SOIL_4,
translation_key="moist_soil_4",
icon="mdi:watering-can-outline",
suggested_display_precision=0,
native_unit_of_measurement=UnitOfPressure.CBAR,
state_class=SensorStateClass.MEASUREMENT,
exclude_api_ver=(ApiVersion.API_V1,),
exclude_data_structure=(
2,
10,
),
aux_sensors=(56,),
),
WLSensorDescription(
key="WetLeaf1",
tag=DataKey.WET_LEAF_1,
translation_key="wet_leaf_1",
icon="mdi:leaf",
suggested_display_precision=1,
state_class=SensorStateClass.MEASUREMENT,
exclude_api_ver=(ApiVersion.API_V1,),
exclude_data_structure=(
2,
10,
),
aux_sensors=(56,),
),
WLSensorDescription(
key="WetLeaf2",
tag=DataKey.WET_LEAF_2,
translation_key="wet_leaf_2",
icon="mdi:leaf",
suggested_display_precision=1,
state_class=SensorStateClass.MEASUREMENT,
exclude_api_ver=(ApiVersion.API_V1,),
exclude_data_structure=(
2,
10,
),
aux_sensors=(56,),
),
WLSensorDescription(
key="Temp1",
tag=DataKey.TEMP_1,
translation_key="temp_1",
suggested_display_precision=1,
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
state_class=SensorStateClass.MEASUREMENT,
exclude_api_ver=(ApiVersion.API_V1,),
exclude_data_structure=(
2,
10,
),
aux_sensors=(56,),
),
WLSensorDescription(
key="Temp2",
tag=DataKey.TEMP_2,
translation_key="temp_2",
suggested_display_precision=1,
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
state_class=SensorStateClass.MEASUREMENT,
exclude_api_ver=(ApiVersion.API_V1,),
exclude_data_structure=(
2,
10,
),
aux_sensors=(56,),
),
WLSensorDescription(
key="Temp3",
tag=DataKey.TEMP_3,
translation_key="temp_3",
suggested_display_precision=1,
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
state_class=SensorStateClass.MEASUREMENT,
exclude_api_ver=(ApiVersion.API_V1,),
exclude_data_structure=(
2,
10,
),
aux_sensors=(56,),
),
WLSensorDescription(
key="Temp4",
tag=DataKey.TEMP_4,
translation_key="temp_4",
suggested_display_precision=1,
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
state_class=SensorStateClass.MEASUREMENT,
exclude_api_ver=(ApiVersion.API_V1,),
exclude_data_structure=(
2,
10,
),
aux_sensors=(56,),
),
)


Expand Down
30 changes: 30 additions & 0 deletions custom_components/weatherlink/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@
"inside_temperature": {
"name": "Inside temperature"
},
"moist_soil_1": {
"name": "Soil moisture 1"
},
"moist_soil_2": {
"name": "Soil moisture 2"
},
"moist_soil_3": {
"name": "Soil moisture 3"
},
"moist_soil_4": {
"name": "Soil moisture 4"
},
"outside_humidity": {
"name": "Outside humidity"
},
Expand Down Expand Up @@ -111,6 +123,18 @@
"supercap_volt": {
"name": "Supercapacitor"
},
"temp_1": {
"name": "Temperature 1"
},
"temp_2": {
"name": "Temperature 2"
},
"temp_3": {
"name": "Temperature 3"
},
"temp_4": {
"name": "Temperature 4"
},
"thsw_index": {
"name": "THSW index"
},
Expand All @@ -126,6 +150,12 @@
"wet_bulb": {
"name": "Wet bulb"
},
"wet_leaf_1": {
"name": "Leaf wetness 1"
},
"wet_leaf_2": {
"name": "Leaf wetness 2"
},
"wind": {
"name": "Wind"
},
Expand Down

0 comments on commit aca52f0

Please sign in to comment.