Page 1 of 1

Developing a plugin - force to publish by controller

Posted: 03 Feb 2019, 23:20
by ember
Hello.
I'm developing custom plugin, and I'm just stuck with this - is there a way to force plugin to publish it's state via MQTT (or to force controller to publish state of this plugin from inside the plugin itself) ?
Or something like rules command

Code: Select all

Publish <topic>, <value>
I tried calling something like this, but it just doesn't seem to work:

Code: Select all

Command_MQTT_Publish(event, "7");
Thanks !

Re: Developing a plugin - force to publish by controller

Posted: 04 Feb 2019, 05:38
by grovkillen
Plugins are not supposed to force anything. You should let the user pick how the communication is working. Why don't you want to use the task setup?

Re: Developing a plugin - force to publish by controller

Posted: 04 Feb 2019, 06:55
by ember
Yes, I know, but I need to notify Home Assistant as soon as the work is done.
I could for example set the update interval to 1s, but the work is being done few times a day, and I don't want to flood mqtt with unnecessary high frequency messages.

Re: Developing a plugin - force to publish by controller

Posted: 04 Feb 2019, 07:14
by grovkillen
First off, don't you worry about flooding MQTT ;)

Second, use rules to push the updates.

Re: Developing a plugin - force to publish by controller

Posted: 04 Feb 2019, 09:06
by ember
Well, by flooding I ment hindering analysis of what's going on with the system, not performance issues :)

That would be one workaround, but then I would have to hardcode topic in this rule, which would be hard to maintenance, considering that i have dozen or so of those units.
Anyway - if there really is no way to enforce controller publish from inside of device plugin - what's the best way to raise an event, that would trigger rule-based mqtt publish ? :)

Re: Developing a plugin - force to publish by controller

Posted: 04 Feb 2019, 19:47
by grovkillen
I'd say it's pretty much equal (or more) maintenance to develop a plugin as doing a rule to do it for you.

What is it you exactly want to accomplish?

Every task will raise an event once a change is made (switch input are as an example not run at intervals). And you could also do task run to trigger events or the event command. But please enlighten me with what exactly you're trying to accomplish. I'm beating around the bush here...

Re: Developing a plugin - force to publish by controller

Posted: 11 Feb 2019, 21:32
by ember
Well, I'm developing plugin that controls covers - two relays and two buttons.
I want it to publish state every 30 seconds when it's idle, and every second when it's operating (cover going either up or down).
UserVar is updated ten times per second.

Re: Developing a plugin - force to publish by controller

Posted: 11 Feb 2019, 21:36
by grovkillen
I'd use a pulse counter that would pulse if it's going up or down. And end switches (limit switches) for 100% up or down.

Re: Developing a plugin - force to publish by controller

Posted: 03 Mar 2019, 15:05
by ember

Code: Select all

sendData(event);
Does the job :)