Developing a plugin - force to publish by controller

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
ember
New user
Posts: 5
Joined: 03 Feb 2019, 23:15

Developing a plugin - force to publish by controller

#1 Post by ember » 03 Feb 2019, 23:20

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 !

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Developing a plugin - force to publish by controller

#2 Post by grovkillen » 04 Feb 2019, 05:38

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?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

ember
New user
Posts: 5
Joined: 03 Feb 2019, 23:15

Re: Developing a plugin - force to publish by controller

#3 Post by ember » 04 Feb 2019, 06:55

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.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Developing a plugin - force to publish by controller

#4 Post by grovkillen » 04 Feb 2019, 07:14

First off, don't you worry about flooding MQTT ;)

Second, use rules to push the updates.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

ember
New user
Posts: 5
Joined: 03 Feb 2019, 23:15

Re: Developing a plugin - force to publish by controller

#5 Post by ember » 04 Feb 2019, 09:06

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 ? :)

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Developing a plugin - force to publish by controller

#6 Post by grovkillen » 04 Feb 2019, 19:47

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...
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

ember
New user
Posts: 5
Joined: 03 Feb 2019, 23:15

Re: Developing a plugin - force to publish by controller

#7 Post by ember » 11 Feb 2019, 21:32

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.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Developing a plugin - force to publish by controller

#8 Post by grovkillen » 11 Feb 2019, 21:36

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.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

ember
New user
Posts: 5
Joined: 03 Feb 2019, 23:15

Re: Developing a plugin - force to publish by controller

#9 Post by ember » 03 Mar 2019, 15:05

Code: Select all

sendData(event);
Does the job :)

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 31 guests