Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zbmini Power On mode #5901

Closed
knowsnotmuch opened this issue Jan 25, 2021 · 20 comments
Closed

Zbmini Power On mode #5901

knowsnotmuch opened this issue Jan 25, 2021 · 20 comments
Labels
feature request Feature request stale Stale issues

Comments

@knowsnotmuch
Copy link

Is your feature request related to a problem? Please describe

When the zbmini powers on, it is by default set to off. This is frustrating if there is a power cut. Or if you want to toggle the power state via a wall switch.

Describe the solution you'd like

Option to set the power state of switches when they boot-up / power on

Describe alternatives you've considered

Node Red rule to set the state. But this creates dependency on one more service and I would prefer that this be localised to the zigbee stack to cut out external dependencies

Additional context

I am not sure if zbmini supports PowerOn OnOff - as per this link it appears to but cant get it to work

@knowsnotmuch knowsnotmuch added the feature request Feature request label Jan 25, 2021
@sjorge
Copy link
Sponsor Contributor

sjorge commented Jan 25, 2021

I don't own the device, but we can try to see if it support the genOnoff startup state....

Update devices.js entry to this.

    {
        zigbeeModel: ['01MINIZB'],
        model: 'ZBMINI',
        vendor: 'SONOFF',
        description: 'Zigbee two way smart switch',
        extend: preset.switch(),
        toZigbee: preset.switch().toZigbee.concat([tz.power_on_behavior]),
        fromZigbee: preset.switch().fromZigbee.concat([fz.power_on_behavior]),
        exposes: [
            e.switch(), exposes.enum('power_on_behavior', ea.ALL, ['off', 'previous', 'on'])
                .withDescription('Controls the behaviour when the device is powered on'),
        ],
        meta: {configureKey: 1},
        configure: async (device, coordinatorEndpoint, logger) => {
            // Has Unknown power source: https://github.com/Koenkk/zigbee2mqtt/issues/5362, force it here.
            device.powerSource = 'Mains (single phase)';
            device.save();
        },
    },

@knowsnotmuch
Copy link
Author

@sjorge thank you for the suggestion. I have a problem with my rpi at the moment. I am trying to get it replaced. Will try soon as I can. But really appreciate the prompt response and suggestion. Thank you!

@knowsnotmuch
Copy link
Author

knowsnotmuch commented Feb 2, 2021

@sjorge - sorry about the delay.

I tried this but got the error below and zigbee2mqtt would not start

> node index.js,
/app/node_modules/zigbee-herdsman-converters/devices.js:12629,
        extend: preset.switch(),,
                             ^,
TypeError: preset.switch is not a function,
    at Object.<anonymous> (/app/node_modules/zigbee-herdsman-converters/devices.js:12629:30),
    at Module._compile (internal/modules/cjs/loader.js:999:30),
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10),
    at Module.load (internal/modules/cjs/loader.js:863:32),
    at Function.Module._load (internal/modules/cjs/loader.js:708:14),
    at Module.require (internal/modules/cjs/loader.js:887:19),
    at require (internal/modules/cjs/helpers.js:74:18),
    at Object.<anonymous> (/app/node_modules/zigbee-herdsman-converters/index.js:3:17),
    at Module._compile (internal/modules/cjs/loader.js:999:30),
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10),
npm ERR! code ELIFECYCLE,
npm ERR! errno 1,
npm ERR! zigbee2mqtt@1.17.0 start: `node index.js`,
npm ERR! Exit status 1,�,

@sjorge
Copy link
Sponsor Contributor

sjorge commented Feb 2, 2021

What version are you running? I remember presets being switched to functions recently ish, so it might be that the version is too old.

@knowsnotmuch
Copy link
Author

knowsnotmuch commented Feb 2, 2021

What version are you running? I remember presets being switched to functions recently ish, so it might be that the version is too old.

@sjorge : using the docker version - I presume it is the latest 1.17.1

PS: firmware version is CC2652R_20210120 (using zzh! stick)

@sjorge
Copy link
Sponsor Contributor

sjorge commented Feb 3, 2021

Are you sure you are on 1.17.1? That was release 2 days ago and should definitely be new enough.

@knowsnotmuch
Copy link
Author

knowsnotmuch commented Feb 3, 2021

Are you sure you are on 1.17.1? That was release 2 days ago and should definitely be new enough.

Yes. I set this up just yesterday to try what you suggested. This is what I see:

{"commit":"99274c7","coordinator":{"meta":{"maintrel":1,"majorrel":2,"minorrel":7,"product":1,"revision":20210120,"transportrev":2},"type":"zStack3x0"},"log_level":"info","network":{"channel":15,"extendedPanID":"0xdddddddddddddddd","panID":6754},"permit_join":true,"version":"1.17.1"}

Let me try again to insert those lines.

@knowsnotmuch
Copy link
Author

I tried again and this time I had no error! Sorry about that.

Now what am I looking for to confirm this made it through @sjorge ? Also, how can I tell if it supports the genOnoff startup status?

@knowsnotmuch
Copy link
Author

@sjorge does not seem to be supported:

Error Publish 'set' 'power_on_behavior' to 'DenFanZ' failed: 'Error: Write 0x847127fffe95f41a/1 genOnOff({"startUpOnOff":1}, {"timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":true,"direction":0,"srcEndpoint":null,"reservedBits":0,"manufacturerCode":null,"transactionSequenceNumber":null}) failed (Status 'UNSUPPORTED_ATTRIBUTE')'

@sjorge
Copy link
Sponsor Contributor

sjorge commented Feb 3, 2021

Yeah if you get UNSUPPORTED_ATTRIBUTE, it's not support :(

I double checked the post you linked, https://github.com/Koenkk/zigbee-herdsman/blob/32cbbcc0a299b81a3b3d2628c5563d9e64dcba0e/src/zcl/definition/cluster.ts#L446 is what power_on_behavior is writing. (16387 decima is 0x4003 in hex)

@knowsnotmuch
Copy link
Author

@sjorge yes - it does look like it is implemented but it does not work. Does that mean that this is a bug? or is the original link I sent wrong?

@sjorge
Copy link
Sponsor Contributor

sjorge commented Feb 3, 2021

z2m is writing the correct attribute, but the device is saying, no, I don't do that.

So the screenshot might be wrong, or it could be readonly instead of rw... hard to say.

@knowsnotmuch
Copy link
Author

Ok - thanks @sjorge. Is there anyway I can write a nodered rule which picks up that a device booted up and set it to power on? Is there some way I can get the "powered up" status ?

Again, thanks for the help and for explaining things. Much appreciate it.

@sjorge
Copy link
Sponsor Contributor

sjorge commented Feb 3, 2021

I think you can trigger a read of 'state' if z2m publishes to /available with true, if the result is off, you can then set it to on?

@knowsnotmuch
Copy link
Author

Ok - will check that. I just saw one more screenshot. Here also, 0x4003 shows as rw:
dresden-elektronik/deconz-rest-plugin#4016 (comment)

@knowsnotmuch
Copy link
Author

knowsnotmuch commented Feb 7, 2021

I think you can trigger a read of 'state' if z2m publishes to /available with true, if the result is off, you can then set it to on?

@sjorge what topic(s) will these show up on? I am not able to spot any message (reliably) to detect device power-on

@sjorge
Copy link
Sponsor Contributor

sjorge commented Feb 7, 2021

They get published to zigbee2mqtt/<friendly_name>/available, I just subscribe to those, if it goes from offline -> online I trigger a /get/state from node-red and set a flow var to indicate I need to check state == ON on the next update.

Then I have a different node that subscribes to zigbee2mqtt/<friendly_name> and when the flow var is set and state != ON, I send a set/state with payload of ON.

@knowsnotmuch
Copy link
Author

thanks for the detailed explanation @sjorge - much appreciate it!

@knowsnotmuch
Copy link
Author

I am trying this, but it looks like there will be a delay to the extent of availability_timeout - is that correct?

I thought this will generate too much traffic and limited it to 60s and the specific device. Is it ok to set a time of say 1s ?

@github-actions
Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Feature request stale Stale issues
Projects
None yet
Development

No branches or pull requests

2 participants