Zigbee2MQTT - Sonoff Wireless Switch (SNZB-01)

Same error for me… when i tap on the button i get

Error: UndefinedError: 'dict object' has no attribute 'to_state'

I have a following problem with blueprint above.

I set an automation for long press with “delay”. It works fine.

Issue I encounter is that button sometimes sends extra action “none”. It cancels my running automation and bypasses triggers from blueprint. Did anyone encounter this problem?

I solved trashing this blueprint to recicle bin and use node-red with zigbee2mqtt monitoring the mqtt topics with payload single, double, long string.
Maybe this blueprint uses some old deprecated methods, no more working.

For anyone still trying to get one of these working in an automation, this seems to be working for me:
Trigger type: MQTT
Topic: zigbee2mqtt/WB1/action (replace WB1 with whatever you named your button)
Payload: single

See screenshot below

Z2M WB1

yes i think it’s the same… but you need to duplicate the trigger and topic string for each automation

This i my Node-Red configurations nodes:

[{"id":"e7f79e0a.203dc","type":"mqtt in","z":"a7b5f465.f2f968","name":"","topic":"zigbee2mqtt/SNZB-01/action","qos":"0","datatype":"auto","broker":"3f412b25.7d88ec","nl":false,"rap":true,"rh":0,"x":190,"y":260,"wires":[["7292c542.0de184"]]},{"id":"7292c542.0de184","type":"switch","z":"a7b5f465.f2f968","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"single","vt":"str"},{"t":"eq","v":"double","vt":"str"},{"t":"eq","v":"long","vt":"str"}],"checkall":"false","repair":false,"outputs":3,"x":410,"y":260,"wires":[["4fa691b5.225a28"],["d1826391.7b5468"],["42ea7350.848e2c"]]},{"id":"4fa691b5.225a28","type":"api-call-service","z":"a7b5f465.f2f968","name":"toggle lumetto","server":"e5fa04da.26da88","version":3,"debugenabled":false,"service_domain":"script","service":"turn_on","entityId":"script.toggle_lumetto_studio","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":600,"y":240,"wires":[[]]},{"id":"d1826391.7b5468","type":"api-call-service","z":"a7b5f465.f2f968","name":"lumetto night","server":"e5fa04da.26da88","version":3,"debugenabled":false,"service_domain":"script","service":"turn_on","entityId":"script.night_mode_lumetto_studio","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":590,"y":300,"wires":[[]]},{"id":"42ea7350.848e2c","type":"api-call-service","z":"a7b5f465.f2f968","name":"lumetto full white","server":"e5fa04da.26da88","version":3,"debugenabled":false,"service_domain":"script","service":"turn_on","entityId":"script.full_white_lumetto_studio","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":610,"y":360,"wires":[[]]},{"id":"78658af9.fd4954","type":"comment","z":"a7b5f465.f2f968","name":"Bridge Zigbeee button sonoff SNZB-01 to HA scripts","info":"Bridge Zigbeee button sonoff SNZB-01 to HA scripts","x":260,"y":200,"wires":[]},{"id":"3f412b25.7d88ec","type":"mqtt-broker","name":"home.linda","broker":"home.linda","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""},{"id":"e5fa04da.26da88","type":"server","name":"Linda HA","version":1,"legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|True|on|home|open","connectionDelay":true,"cacheJson":true}]
3 Likes

@Stringer i love this blueprint. I would like to use it to open and close a cover. But just with a single click.
That would mean a toggle function. I am not keen enough to change the blueprint myself.
Would it be possible for you to adjust this blueprint to add a toggle function?
First press: the cover opens and later a first press, the cover closes.

I know, i could use the single press for open and the double press for close, but that has a lesser WAF.

So I’m finally getting back to my zigbee wireless switches after changing to the SONOFF Zigbee 3.0 USB Dongle Plus and moving from ZHA to zigbee2mqtt, since I was having the disconnection and battery drain issues that others were expecting…

However, this blueprint doesn’t work for me. I’m new enough to HA that I don’t understand a lot of this, but was able to get a bare automation working, so I know things can work, but I don’t see anything hit the automation trace. Any assistance would be helpful. I’m not sure how to troubleshoot.

(as evidenced by the post below I’m super new to HA so I could be entirely off base here)

If you’ve got a way to determine the state of the cover (open vs closed) you should be able to put some conditions in there to open it if it’s closed and vice versa. Alternatively, if you needed to track that, helpers seem like the way to go. You should be able to do that without needing to touch the blueprint. Hopefully, that helps.

Hi, I have installed this blueprint, but, although my device is enabled, I cannot select it in the blueprint device. Is there something I must do with mqtt??

I got this device info:

Zigbee info
IEEE: 00:12:4b:00:24:ce:5e:16
Nwk: 0xc426
Device Type: EndDevice
LQI: 27
RSSI: Unknown
Last Seen: 2022-05-28T20:20:34
Power Source: Battery or Unknown
Quirk: zhaquirks.sonoff.button.SonoffButton

Instead of the button turning on the switch, have it turn on a toggle helper (input_boolean). Then another automation that watches for the input boolean state and changes the switch to match.
Open your Home Assistant instance and show your helper entities.

My suggestion to ‘fix’ the null triggering problem is to add a trigger condition that only allows valid triggers thru to the actions. Z2M sends these null triggers out as part of the way it is designed, so screening them is important. For this one a condition block after the trigger would make your users very happy…

condition:
  condition: template
  value_template: '{{ trigger.to_state.attributes.action in ( ''single'',''double'',''long'') }}'

That will clean up everyone’s log and the only place you see them is if you look at the traces, there will be triggers that happen but fail the condition and die.

Due to requests, I wrote the condition for you…
I hope the author adds this to the actual blueprint, I cannot. However if users manually edit their copy of the blueprint code adding the condition after th trigger, it should only run the blueprint code if one of these things happen, Other event will trigger the blueprint but fai the condition and no nothing. If you stil cannot see traces in the default 5 allotted to fix your stuff, just add to the automation that calls the script a line to store more traces…

condition:
  condition: template
  value_template: '{{ trigger.to_state.attributes.action in ( ''single'',''double'',''triple'',''quadruple'',''hold'',''release'',''shake'',''single_left'',''double_left'',''triple_left'',''hold_left'',''release_left'',''single_right'',''double_right'',''triple_right'',''hold_right'',''release_right'',''single_center'',''double_center'',''triple_center'',''hold_center'',''release_center'',''single_both'',''double_both'',''triple_both'',''hold_both'',''release_both'') }}'

3 Likes

@Sir_Goodenough

Would you please explain how to add this for us newbs? Greatly appreciated

I believe this condition block as is added immediately after the trigger block should work.
I have not tested it with this blueprint, but it works in principal in several of my Z2M blueprints.

The actual problem that few people realize it that if you write a single automation and look for a specific trigger, this works fine without null triggers.

In the case of a blueprint like this, the author screens for 3 triggers, but there are actually 4 valid triggers. Every time it is triggered as a short, double, or long, after a time it triggers again as a null trigger to reset for the next short, double, or long. Null is a valid trigger and happens every time. Therefore you have to account for it or the null trigger gets dumped into the blueprint with nowhere to go and becomes a log error.

What the condition does is allows thru only the 3 valid things the blueprint is looking for, and when the null one shows up, it just fails the condition and goes away quietly. The only place it then shows is as a mostly blank trace.

If there are too many null triggers for you to troubleshoot a problem, you can increase the number of traces for this automation, which in the case of my Z2M cube and other switches I do.

Links about stored_traces—>

1 Like

For me is OK, but little modify.
DELETE: “attribute: action” (in trigger block) → because it is not attribute but sensor (you must choice sensor with “action” on the end of name)
and replace quotation marks, because import changed it. Must be:

action:
- variables:
    command: '{{ trigger.to_state.state }}'
- choose:
  - conditions:
    - "{{ command == 'single' }}"
    sequence: !input single_press
  - conditions:
    - "{{ command == 'double' }}"
    sequence: !input double_press
  - conditions:
    - "{{ command == 'long' }}"
    sequence: !input long_press

I modified with File editor in blueprints/automation/Stringer
And reload automations!

And thats it.

3 Likes

I am having this problem too, did you find a solution?

hello,
blueprint works perfectly but I would like to send a notification when there is a click on the button.
The button action works but I don’t get the notification.
Do you know why ?

alias: Bouton veilleuse Ethan
description: “”
use_blueprint:
path: AramidX/sonoff_snzb01_wireless_switch_z2m.yaml
input:
switch: sensor.bouton_veilleuse_ethan_action
single_press:
- type: turn_on
device_id: ccae2db0bd0034154045fe7ecaef7315
entity_id: switch.prise_veilleuse_ethan
domain: switch
- service: notify.mobile_app_pocof3kevin
data:
message: Veilleuse allumée
double_press:
- type: turn_off
device_id: ccae2db0bd0034154045fe7ecaef7315
entity_id: switch.prise_veilleuse_ethan
domain: switch

Thanks in advance

Hi have a odd problem, when i use blueprint, put my sonoff switch in entities, save it to automation it dont save it?
If i put sonoff_button1_aktion in entities it saves but not work, but when i put sonoff_button1 in entities the automation dissapear ??

The solution I found is to use a different blueprint which is really working:

2 Likes

Old topic, old issue (probably since August z2m update) but maybe it help someone.
I had problem to trigger action because it was ending with unknown reason “null”. It was issue with restart mode of automation when it was triggered by button release action.

So simple fix is to change mode to queued or single.