Skip to content

Commit

Permalink
Option to write to CSV file
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeweerd committed Feb 1, 2022
1 parent d85b61a commit 2cb31ba
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <timestamp>,<name|attr_id>,<value>,<attr_id>,<cluster_id>,<ep_id>,<ieee>,<manf_id>
# 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.
Expand Down
6 changes: 4 additions & 2 deletions custom_components/zha_toolkit/zcl_attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 2cb31ba

Please sign in to comment.