Thank you so much for sharing your configuration.I had to do some syntax adjustments to the MachMd sensor but it work. Namely:
- adding escaped quotes to the URL queried by curl
command: "curl -s \"http://192.168.202.156/http-read.json?encrypted=0\" | jq .statusLavatrice.MachMd"
- removing the cast to int at the end of value_template
value_template: '{{ value | replace("\"", "") }}'
Unfortunately for me it’s too hit and miss. It could be that the timing needs adjusting but I suspect that the culprit is the curl script that does not always answer. I monitor the state from the terminal when I’m debugging and I don’t always get an answer.
I still don’t get why the automation is not triggered, maybe when the curl request fails the sensor state becomes undefined or blank therefore there is no 2 -> 7 transition but 2 -> ? -> 7
Maybe the template needs to default to “2” in case of timeout?
I’m debugging this with 2 -> 3 (Paused) and the automation is triggered roughly 50% of the times.
I would like to fine-tune your configuration because it basically works.
Otherwise I’d have to resort to something more reliable but a lot more complicated, i.e. sniffing the packet that the machine sends to the Candy Cloud when it’s finished.
I already did that, if someone’s interested:
<machine_ip> -> 52.213.231.49 HTTP
[truncated]GET /api/av1/listen.json?macAddress=XXXXXXXXXXX&encrypted=0&macAddress=XXXXXXXXXXXX&WiFiStatus=0&Err=0&MachMd=7&Pr=1&PrPh=0&PrCode=0&SLevel=0&Temp=40&SpinSp=10&Opt1=0&Opt2=0&Opt3=0&Opt4=0&Opt5=0&Opt6=0&Opt7=0&Opt8=0&Opt9=0&St
Host: simplyfimgmt.candy-hoover.com
This however is way more complicated and probably not even doable if you don’t have the proper hardware. Your router needs to be able to run some kind of script and trigger some other mechanism that Home Assistant can read reliably.
***** EDIT ***** 16/03/2021
I think I got this to work by lowering the polling frequency of the sensor and increasing the timeout. I also got rid of the binary sensor and I integrated the ping in the command sensor. Here’s my code:
sensor:
- platform: command_line
name: Candy MachMd
command: "ip=192.168.1.10; ping $ip -c 1 -W 2 > /dev/null; if [ $? -eq 0 ]; then res=$(curl -s \"http://$ip/http-read.json?encrypted=0\"); if [ $? -eq 0 ]; then echo $res | jq .statusLavatrice.MachMd; else echo \"\"999\"\"; fi; else echo \"\"0\"\"; fi"
scan_interval: 60
command_timeout: 29
value_template: '{{ value | replace("\"", "") }}'
The readability is not great but basically it works like this:
no ping response -> 0
ping response but empty or no curl response -> 999
ping response, curl response -> value of MachMd
This way I figured out that during wash I was getting 2 / 999 / 2 / 999 / 2 / 999 / 7 / 999 / 7 / 999
I was polling every 30 seconds with 10 seconds timeout. Now I interrogate the machine every 60 seconds and I wait 29 seconds before timeout. I only tried it once so far but I got no 999 and the automation worked.