Skip to content

Commit

Permalink
Add support for minimal_valve_position parameter for Shelly Valve (#…
Browse files Browse the repository at this point in the history
…503)

* Add support for minimum_valve_position parameter

* Update docs, change minimum to minimal

* Update info.md
  • Loading branch information
bieniu committed Dec 19, 2023
1 parent 2c10cd9 commit 5cc4068
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,11 @@ key | optional | type | default | possible values | description
`ext-switch` | True | boolean | `false` | `true`, `false` | presence of external switch
`force_update_sensors` | True | boolean | `false` | `true`, `false` | [force update](https://www.home-assistant.io/integrations/sensor.mqtt/#force_update) for sensors
`powered` | True | string | `battery` | `ac`, `battery` | `ac` or `battery` powered for Shelly H&T, Motion, Sense and Button1
`expire_after` | True | integer | 51840 | | [expire after](https://www.home-assistant.io/integrations/binary_sensor.mqtt/#expire_after) for battery powered sensors in seconds
`expire_after` | True | integer | `51840` | | [expire after](https://www.home-assistant.io/integrations/binary_sensor.mqtt/#expire_after) for battery powered sensors in seconds
`use_fahrenheit` | True | boolean | `false` | `true`, `false` | whether the temperature sensor is configured in Fahrenheit for H&T, Flood, Motion2 or DW2
`default_heating_temperature` | True | float | `20` | | default target temperature after changing from OFF to HEAT mode
`minimal_valve_position` | True | int | `0` | | this value should be equal to the MINIMAL VALVE POSITION LIMIT from Shelly Valve configuration


[releases]: https://github.com/bieniu/ha-shellies-discovery/releases
[releases-shield]: https://img.shields.io/github/release/bieniu/ha-shellies-discovery.svg?style=popout
Expand Down
3 changes: 2 additions & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,10 @@ key | optional | type | default | possible values | description
`ext-switch` | True | boolean | `false` | `true`, `false` | presence of external switch
`force_update_sensors` | True | boolean | `false` | `true`, `false` | [force update](https://www.home-assistant.io/integrations/sensor.mqtt/#force_update) for sensors
`powered` | True | string | `battery` | `ac`, `battery` | `ac` or `battery` powered for Shelly H&T, Motion, Sense and Button1
`expire_after` | True | integer | 51840 | | [expire after](https://www.home-assistant.io/integrations/binary_sensor.mqtt/#expire_after) for battery powered sensors in seconds
`expire_after` | True | integer | `51840` | | [expire after](https://www.home-assistant.io/integrations/binary_sensor.mqtt/#expire_after) for battery powered sensors in seconds
`use_fahrenheit` | True | boolean | `false` | `true`, `false` | whether the temperature sensor is configured in Fahrenheit for H&T, Flood, Motion2 or DW2
`default_heating_temperature` | True | float | `20` | | default target temperature after changing from OFF to HEAT mode
`minimal_valve_position` | True | int | `0` | | this value should be equal to the MINIMAL VALVE POSITION LIMIT from Shelly Valve configuration

[forum]: https://community.home-assistant.io/t/shellies-discovery-script/94048
[forum-shield]: https://img.shields.io/badge/community-forum-brightgreen.svg?style=popout
Expand Down
15 changes: 11 additions & 4 deletions python_scripts/shellies_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
CONF_IGNORE_DEVICE_MODEL = "ignore_device_model"
CONF_IGNORED_DEVICES = "ignored_devices"
CONF_MAC = "mac"
CONF_MINIMAL_VALVE_POSITION = "minimal_valve_position"
CONF_MODE = "mode"
CONF_MODEL_ID = "model"
CONF_OPTIMISTIC = "optimistic"
Expand Down Expand Up @@ -225,8 +226,8 @@
# Firmware 2.1.4-rc1 release date
MIN_MOTION2_FIRMWARE_DATE = 20220301

# Firmware 2.1.6 release date
MIN_VALVE_FIRMWARE_DATE = 20220612
# Firmware 2.2.1 release date
MIN_VALVE_FIRMWARE_DATE = 20231009

# Firmware 1.11.7 release date
MIN_DIMMER_FIRMWARE_DATE = 20211109
Expand Down Expand Up @@ -521,7 +522,7 @@
TOPIC_WHITE_STATUS = "~white/{light_id}/status"

TPL_ACCELERATED_HEATING = "{{value_json.thermostats.0.target_t.accelerated_heating}}"
TPL_ACTION_TEMPLATE = "{{%if value_json.thermostats.0.target_t.value<={min_temp}%}}off{{%elif value_json.thermostats.0.pos==0%}}idle{{%else%}}heating{{%endif%}}"
TPL_ACTION_TEMPLATE = "{{%if value_json.thermostats.0.target_t.value<={min_temp}%}}off{{%elif value_json.thermostats.0.pos=={min_pos}%}}idle{{%else%}}heating{{%endif%}}"
TPL_AUTOMATIC_TEMPERATURE_CONTROL = (
"{%if value_json.target_t.enabled%}ON{%else%}OFF{%endif%}"
)
Expand Down Expand Up @@ -2642,6 +2643,11 @@ def mqtt_publish(topic, payload, retain, json=False):
# climate entities
if climate_entity_option:
default_heat_temp = 20
minimal_valve_position = device_config.get(CONF_MINIMAL_VALVE_POSITION, 0)
if not isinstance(minimal_valve_position, int):
raise TypeError(
f"minimal_valve_position value {minimal_valve_position} is not an integer, check script configuration"
)
if device_config.get(CONF_DEFAULT_HEAT_TEMP):
value = device_config[CONF_DEFAULT_HEAT_TEMP]
if (
Expand All @@ -2665,7 +2671,8 @@ def mqtt_publish(topic, payload, retain, json=False):
payload = {
KEY_ACTION_TOPIC: TOPIC_INFO,
KEY_ACTION_TEMPLATE: TPL_ACTION_TEMPLATE.format(
min_temp=climate_entity_option[KEY_MIN_TEMP]
min_temp=climate_entity_option[KEY_MIN_TEMP],
min_pos=minimal_valve_position,
),
KEY_CURRENT_TEMPERATURE_TOPIC: TOPIC_INFO,
KEY_CURRENT_TEMPERATURE_TEMPLATE: TPL_CURRENT_TEMPERATURE,
Expand Down

0 comments on commit 5cc4068

Please sign in to comment.