TOGGLE widget does not toggle dimmer

New thread as requested by @mueller-ma.

I created a toggle widget on my Galaxy s9+ with the new Android App Beta but tapping it has no effect on the dimmer light.

Investigation so far:

curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "OFF" "http://127.0.0.1:8080/rest/items/DimmerBathroomCeilingLights_Dimmer"

turns the lights off.

curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "ON" "http://127.0.0.1:8080/rest/items/DimmerBathroomCeilingLights_Dimmer"

turns them on.

curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "TOGGLE" "http://127.0.0.1:8080/rest/items/DimmerBathroomCeilingLights_Dimmer"

Has no effect on the lights.

Could you show us the openHAB events.log for these cases?

curl commands:

higgers@ha5:~$ date && curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "100" "http://127.0.0.1:8080/rest/items/DimmerBathroomCeilingLights_Dimmer"
Fri 06 Sep 2019 06:15:07 PM BST
higgers@ha5:~$ date && curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "0" "http://127.0.0.1:8080/rest/items/DimmerBathroomCeilingLights_Dimmer"
Fri 06 Sep 2019 06:15:09 PM BST
higgers@ha5:~$ date && curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "TOGGLE" "http://127.0.0.1:8080/rest/items/DimmerBathroomCeilingLights_Dimmer"
Fri 06 Sep 2019 06:15:11 PM BST
higgers@ha5:~$ date && curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "TOGGLE" "http://127.0.0.1:8080/rest/items/DimmerBathroomCeilingLights_Dimmer"
Fri 06 Sep 2019 06:15:13 PM BST
higgers@ha5:~$ date && curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "TOGGLE" "http://127.0.0.1:8080/rest/items/DimmerBathroomCeilingLights_Dimmer"
Fri 06 Sep 2019 06:15:14 PM BST
higgers@ha5:~$ date && curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "TOGGLE" "http://127.0.0.1:8080/rest/items/DimmerBathroomCeilingLights_Dimmer"
Fri 06 Sep 2019 06:15:15 PM BST

Events log:

2019-09-06 18:15:07.416 [ome.event.ItemCommandEvent] - Item 'DimmerBathroomCeilingLights_Dimmer' received command 100
2019-09-06 18:15:07.416 [nt.ItemStatePredictedEvent] - DimmerBathroomCeilingLights_Dimmer predicted to become 100
2019-09-06 18:15:07.417 [vent.ItemStateChangedEvent] - DimmerBathroomCeilingLights_Dimmer changed from 0 to 100
2019-09-06 18:15:09.555 [ome.event.ItemCommandEvent] - Item 'DimmerBathroomCeilingLights_Dimmer' received command 0
2019-09-06 18:15:09.556 [nt.ItemStatePredictedEvent] - DimmerBathroomCeilingLights_Dimmer predicted to become 0
2019-09-06 18:15:09.557 [vent.ItemStateChangedEvent] - DimmerBathroomCeilingLights_Dimmer changed from 100 to 0
2019-09-06 18:15:11.714 [ome.event.ItemCommandEvent] - Item 'DimmerBathroomCeilingLights_Dimmer' received command DOWN
2019-09-06 18:15:13.940 [ome.event.ItemCommandEvent] - Item 'DimmerBathroomCeilingLights_Dimmer' received command DOWN
2019-09-06 18:15:14.766 [ome.event.ItemCommandEvent] - Item 'DimmerBathroomCeilingLights_Dimmer' received command DOWN
2019-09-06 18:15:15.786 [ome.event.ItemCommandEvent] - Item 'DimmerBathroomCeilingLights_Dimmer' received command DOWN

There you go, the TOGGLE command does not get to your Item.

Guessing your Item is a Dimmer type, It does not support TOGGLE commands.

It’s a bit weird it seems to get transformed to a DOWN - I would expect just an error for a command mismatch. That seems to be a bug.

Had a play with this (OH2.4)

Switch type Item - no documented TOGGLE command.
From REST API, you can send ON , OFF and get the expected result.
You can send nonsense like RHUBARB, response 400 and is ignored.
But you can also command TOGGLE and get response 200, accepted. And the switch state will toggle OFF->ON, ON->OFF,
However, some hidden actor is doing that … what actually arrives on OH events bus is an ON or OFF, never a TOGGLE.
I know little of REST endpoints but there looks to be a “special” one for TOGGLE.
openHAB Item itself does not support TOGGLE.

Okay, doing a similar exercise for a Dimmer type, similar results. Except that the mystery actor converts TOGGLE to UP / DOWN commands which are ignored by Dimmer Item type.

Conclusion, the REST endpoint isn’t dealing properly with TOGGLE for Dimmer type. It’s open to debate what exactly is a “toggle” of a dimmer at e.g. 75%, but presumably similar actions to autoupdate dealing with ON/OFF might be acceptable. Or perhaps the endpoint is not intended for dimmers at all, and should bounce the command with a 400 response.

1 Like

Reading that linked issue report and the PR discussion linked from there, I guess the best idea is us implementing this completely client side and not using the TOGGLE command at all. After doing so it looks like the maintainers are happy to nuke TOGGLE command support from the code base.

I read the issue too and agree that it does look like TOGGLE is going to be removed at some point.

What logic would you use to implement TOGGLE for a dimmer? Read the current state of the dimmer and it it’s >0 set to OFF else set to ON?

I don’t know if all dimmers work the way mine do. My dimmers remember the last setting they were set to when they were on. I.e., if you dim them to, for example, 33% then turn them off and then turn them on they return to 33%. This means that issuing a sequence of OFF and ON commands toggles them between off and the previous brightness setting.

If your UI issues ON and OFF commands, this should all “come out in the wash” when the ON/OFF arrives at the binding. It is the binding that understands the hardware and should make the decision to actually send an ON or 100% etc. to the device.

Yes, exactly that.

Cool. Feel free to ask me to test.