Open tunerooster opened 4 months ago
When used in automations, if you want a reply, you need to add expect_reply. I'ld expect that at best that is possible in the HA webservice as well.
If not, we would need to check the documentation how an integration can impact the web reply.
Other approaches I think of:
Thanks for your reply! My main reason for doing this is to determine if the zigbee decice is connected. The device occasionally drops out, and I want to determine (in a script) if that has happened, without changing the state of the device. When I query the device state directly, if replies "on" even if the device is powered off (unplugged). Also, reading from the cache would not likely serve my purpose for the same reason. I will look into the references you suggest...
Where do you put the "expect_reply" in the call to curl? Like this:
curl -H "$BEARERAUTH" -H "Content-Type: application/json" -d '{"ieee": "switch.tz3210_j4pdtz9v_ts0001_switch", "endpoint": 1, "cluster": 0, "attribute": 3, "expect_reply": "true"}' http://homeassistant:8123/api/services/zha_toolkit/attr_read
The above expect_reply did not work. Same "[]" response.
Do you know of any better ways to test the zigbee connection status? Thanks again!
You could also look into the webhooks functionnality.
I made a mistake about expect_reply - that's to indicate that the service call should wait for a reply for the device (I did not check again).
The option is actually "response_variable" for use in scripts, so maybe you can set that in your request.
The functionality for the response data was announced here and implemented in zha-toolkit at about that period: https://www.home-assistant.io/blog/2023/07/05/release-20237/
Here are two other approaches:
See https://github.com/mdeweerd/zha-toolkit/blob/main/examples/script_read_basic_cluster.yaml for an example where a value is read and written to a CSV file that is put in a file accessible as a URL.
As you can write values read directly to a state, you could update a state on a regular basis and read that state using the W.
See https://github.com/mdeweerd/zha-toolkit/blob/main/examples/script_use_zha_devices_response.yaml . You can use that information to help determine the state of your device and report it.
Use the ha_set_state service from zha-toolkit to update a state that you can read through the web service.
I tried this, as you suggested, but still no data:
curl -H "$BEARERAUTH" -H "Content-Type: application/json" -d '{"ieee": "switcurl -H "$BEARERAUTH" -H "Content-Type: application/json" -d '{"ieee": "switch.tz3210_j4pdtz9v_ts0001_switch", "endpoint": 1, "cluster": 0, "attribute": 3, "response_variable": "true"}' http://homeassistant:8123/api/services/zha_toolkit/attr_read
ch.tz3210_j4pdtz9v_ts0001_switch", "endpoint": 1, "cluster": 0, "attribute": 3, "response_variable": "true"}' http://homeassistant:8123/api/services/zha_toolkit/attr_read
[]
Is the curl call correct? What should the value of "response_variable" be?
It is possible that the HA web interface does not return a value. The value for response_variable is a string here which is ok because the value is the name of the variable to set, however, "true" may not be an accepted name for a variable.
I can't afford to change the state of the device, as any change will trigger/activate the device. (It is a fingerbot which interprets any on/off/toggle of its state to be a "click" and a button is pushed which turns on/off another device.)
Are you saying to use a HA script to call the service and output the data using csvout: "{{ csv }}"? Is "csvout" a zha_toolkit attribute? I'm not quite understanding, even looking at the script_read_basic_cluster.yaml script.
The response_variable sounds the most promising, but I can't see how to use it, even after reading the reference you provided.
I very much appreciate your help!
I can't afford to change the state of the device, ...
That's not what I am suggesting - you can create another entity/state with the value that you want to observe.
Are you saying to use a HA script to call the service and output the data using csvout: "{{ csv }}"? Is "csvout" a zha_toolkit attribute?
'csvout' is a parameter to several zha-toolkit services - including the read attribute - it will write the information to the indicated CSV file. "{{ csv }}" is a template indicating to Home Assistant to return the value of 'csv' which is an input/parameter to the example script.
The response_variable sounds the most promising, but I can't see how to use it, even after reading the reference you provided.
Maybe the response is not available in a simple curl request - I guess it is available if you are using a websocket (which means that you have a continuous connection). I shared the python script I developed for another project that could help with that - but it seems to be above your skillset.
Thanks for your explanation. I will keep trying. But yes, it's challenging for me. Best regards!
On Sat, Feb 17, 2024, 4:57 AM MDW @.***> wrote:
I can't afford to change the state of the device, ...
That's not what I am suggesting - you can create another entity/state with the value that you want to observe.
Are you saying to use a HA script to call the service and output the data using csvout: "{{ csv }}"? Is "csvout" a zha_toolkit attribute?
'csvout' is a parameter to several zha-toolkit services - including the read attribute - it will write the information to the indicated CSV file. "{{ csv }}" is a template indicating to Home Assistant to return the value of 'csv' which is an input/parameter to the example script.
The response_variable sounds the most promising, but I can't see how to use it, even after reading the reference you provided.
Maybe the response is not available in a simple curl request - I guess it is available if you are using a websocket (which means that you have a continuous connection). I shared the python script I developed for another project that could help with that - but it seems to be above your skillset.
— Reply to this email directly, view it on GitHub https://github.com/mdeweerd/zha-toolkit/issues/220#issuecomment-1949983935, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADFMVIVZDSQSLS5ETWRGU23YUCLMLAVCNFSM6AAAAABDM5FDMWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBZHE4DGOJTGU . You are receiving this because you authored the thread.Message ID: @.***>
I am trying to use curl to read a zigbee attribute from a device.
From within Home Assistant, it works. I.e., this service request:
Returns this response:
However when I try to do the same thing via the Home Assistant API, as follows:
It prints only:
Which means the request succeeded, but there is no data in the response. I want to get a full json response with the same data as the Home Assistant interactive service request.
Any advice is appreciated!