-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from mdeweerd/dev
Add ha_set_state
- Loading branch information
Showing
10 changed files
with
355 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
- `backup.yaml`:\ | ||
Script for daily backup of supported zigbee coordinators. | ||
- `backup_znp.yaml`:\ | ||
Script for daily backup of ZNP coordinator. | ||
- `blueprint_danfoss_ally_configure_script.yaml`:\ | ||
Sample blueprint script | ||
to configure Danfoss Ally (see other script example for a more complete | ||
configuration) | ||
- `danfoss_ally_remote_temperature.yaml`:\ | ||
Send temperature to Danfoss Ally | ||
TRV at most every X minutes and at least every Y minutes. Uses restart to | ||
interrupt long wait ("y minutes") | ||
- `danfoss_ally_remote_temperature_min_delay.yaml`:\ | ||
Send temperature to | ||
Danfoss Ally at most every X minutes. Uses single to block too fast | ||
updates. In case the temperature is stable over a very long time, you | ||
should ensure that HA considers it is updated on every change. | ||
- `danfoss_ally_remote_temperature_min_delay_fake_change.yaml`:\ | ||
Same as | ||
`..._min_delay.yaml`. Work in progress - needs update of | ||
`home-assistant-variables`. Uses | ||
[snarky-snark/home-assistant-variables](https://github.com/snarky-snark/home-assistant-variables) | ||
to fake temperature update even when stable by applying slight change in | ||
temperature at the end of the minimum delay. So if the temperature is | ||
stable, it will still be seen as a change. | ||
- `script_Thermometer_setReporting.yaml`:\ | ||
Blueprint Script to configure | ||
reporting of a zigbee device with Temperature Measurement Cluster 0x0402. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
blueprint: | ||
domain: automation | ||
name: Ally Temp Update Min Delay | ||
description: Update Danfoss Ally TRV external temperature with min refresh rate | ||
source_url: https://github.com/mdeweerd/zha-toolkit/blob/master/blueprints/danfoss_ally_remote_temperature_min_delay.yaml | ||
input: | ||
ally_device: | ||
name: Ally TRV Device | ||
description: Temperature reading will be sent to this device | ||
selector: | ||
device: | ||
manufacturer: Danfoss | ||
entity: | ||
domain: climate | ||
temp_sensor_id: | ||
name: Temperature Sensor | ||
description: External sensor from which the temperature will be read. Expects | ||
data format 12.3 (corresponding to °C) | ||
selector: | ||
entity: | ||
device_class: temperature | ||
min_update_minutes: | ||
name: Minimum update interval | ||
description: > | ||
Updates will not be sent if time from last update is less than minimum interval. | ||
Normally 30 min for uncovered, 5 min for covered. | ||
default: 5 | ||
selector: | ||
number: | ||
max: 299 | ||
min: 1 | ||
unit_of_measurement: minutes | ||
mode: box | ||
temperature_offset: | ||
name: Temperature offset to apply to temperature measured by sensor | ||
description: > | ||
When the offset is -1.5 and the value measured by the sensor is 20 °C, then | ||
the temperature provide to the TRV will be 18.5 °C. | ||
default: 0 | ||
selector: | ||
number: | ||
max: 4.0 | ||
min: -4.0 | ||
step: 0.1 | ||
unit_of_measurement: °C | ||
mode: box | ||
variables: | ||
device: !input ally_device | ||
ieee: "{{(device_attr(device, 'identifiers')|list)[0][1]}}" | ||
min_update_minutes: !input min_update_minutes | ||
temp_sensor_id: !input temp_sensor_id | ||
temp_offset: !input temperature_offset | ||
trigger: | ||
- platform: state | ||
entity_id: | ||
- !input temp_sensor_id | ||
action: | ||
- alias: Write remote temperature to Danfoss Ally | ||
service: zha_toolkit.attr_write | ||
data: | ||
ieee: '{{ ieee }}' | ||
cluster: 0x0201 | ||
attribute: 0x4015 | ||
attr_val: '{{ (((states(temp_sensor_id)|float) + temp_offset) * 100) | round(0) | ||
}}' | ||
read_before_write: false | ||
- alias: Wait until the minimum update delay expires (automation restarts when temperature | ||
changes before) | ||
delay: | ||
minutes: !input min_update_minutes | ||
- alias: Fake small change in temperature so that the next sensor update triggers an update/change event | ||
service: zha_toolkit.ha_set_state | ||
data: | ||
state_id: '{{ temp_sensor_id }}' | ||
attr_val: '{{ (states(temp_sensor_id)|round(2)) + 0.001 }}' | ||
|
||
mode: single |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
|
||
from homeassistant.helpers.template import Template | ||
from homeassistant.util import dt as dt_util | ||
|
||
from . import utils as u | ||
from .params import INTERNAL_PARAMS as p | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def ha_set_state( # noqa: C901 | ||
app, listener, ieee, cmd, data, service, params, event_data | ||
): | ||
success = True | ||
|
||
val = params[p.ATTR_VAL] | ||
state_field = None | ||
|
||
state_template_str = params[p.STATE_VALUE_TEMPLATE] | ||
if state_template_str is not None: | ||
template = Template("{{ " + state_template_str + " }}", listener._hass) | ||
new_value = template.async_render(value=val, attr_val=val) | ||
val = new_value | ||
|
||
# Write value to provided state or state attribute | ||
if params[p.STATE_ID] is None: | ||
raise ValueError("'state_id' is required") | ||
|
||
if params[p.STATE_ATTR] is not None: | ||
state_field = f"{params[p.STATE_ID]}[{params[p.STATE_ATTR]}]" | ||
else: | ||
state_field = f"{params[p.STATE_ID]}" | ||
|
||
LOGGER.debug( | ||
"Set state '%s' -> %s", | ||
state_field, | ||
val, | ||
) | ||
u.set_state( | ||
listener._hass, | ||
params[p.STATE_ID], | ||
val, | ||
key=params[p.STATE_ATTR], | ||
allow_create=params[p.ALLOW_CREATE], | ||
) | ||
|
||
event_data["success"] = success | ||
|
||
if success and (params[p.CSV_FILE] is not None): | ||
fields = [] | ||
label = params[p.CSV_LABEL] | ||
|
||
fields.append(dt_util.utcnow().isoformat()) | ||
fields.append(state_field) | ||
fields.append(val) | ||
fields.append(label) | ||
|
||
u.append_to_csvfile( | ||
fields, | ||
"csv", | ||
params[p.CSV_FILE], | ||
f"{state_field}={val}", | ||
listener=listener, | ||
) | ||
LOGGER.debug(f"ha_set_state info Written to CSV {params[p.CSV_FILE]}") | ||
|
||
if u.isJsonable(val): | ||
val = repr(val) | ||
|
||
# For internal use | ||
return success |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.