From 2cb31ba30fae68ba77ef841e4bb217d22a4682d7 Mon Sep 17 00:00:00 2001 From: mdeweerd Date: Tue, 1 Feb 2022 01:15:47 +0100 Subject: [PATCH] Option to write to CSV file --- README.md | 28 +++++++++++++++++++++++ custom_components/zha_toolkit/zcl_attr.py | 6 +++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0414d93..bf50cc3 100644 --- a/README.md +++ b/README.md @@ -290,8 +290,36 @@ data: allow_create: True # The manufacturer should be set only for manufacturer attributes manf: 0x1212 + # Write read value to CSV file + # Can be useful in automation/script + # Format: ,,,,,,, + # Optional: CSV file to write attribute to - located in /config/csv/... + csvout: testcsv.csv + # optional: csvlabel (default label = name from zigpy or attribute id) + csvlabel: MyAttributeLabel ``` + +Example: read with write to CSV file +```yaml +service: zha_toolkit.execute +data: + command: attr_read + ieee: light.texasinstruments_ti_samplelight_d77add01_level_light_color_on_off + event_done: zha_done + attribute: 0 + cluster: 0 + csvout: testcsv.csv +``` + +Example of CSV output in /config/csv/testcsv.csv (header may be added in the future) +```csv +2022-02-01T00:10:50.202707+00:00,zcl_version,1,0x0000,0x0000,11,00:12:4b:00:01:dd:7a:d7, +``` + + + + ## `attr_write`: Write(/Read) an attribute value Write an attribute value to any endpoint/cluster/attribute. diff --git a/custom_components/zha_toolkit/zcl_attr.py b/custom_components/zha_toolkit/zcl_attr.py index 4707e20..0390f3a 100644 --- a/custom_components/zha_toolkit/zcl_attr.py +++ b/custom_components/zha_toolkit/zcl_attr.py @@ -334,11 +334,13 @@ async def attr_write( fields.append(dt_util.utcnow().isoformat()) fields.append(attr_name) fields.append(read_val) - fields.append("0x%04X" % (attr_id) ), + fields.append("0x%04X" % (attr_id)), fields.append("0x%04X" % (cluster.cluster_id)), fields.append(cluster.endpoint.endpoint_id) fields.append(str(cluster.endpoint.device.ieee)) - fields.append(("0x%04X" % (params[MANF])) if params[MANF] is not None else "") + fields.append( + ("0x%04X" % (params[MANF])) if params[MANF] is not None else "" + ) u.append_to_csvfile( fields, "csv",