Making EspEasy a little bit more useable with ioBroker

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
moelski
Normal user
Posts: 161
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Making EspEasy a little bit more useable with ioBroker

#1 Post by moelski » 27 Sep 2020, 09:42

Hi !

This text could be a little bit longer ... Sorry for that 8-)

Yesterday I started to take a look at EspEasy again. I was using it 4 years ago and at that time I wrote the candle plugin for EspEasy.
My goal was to include some of my switchable power plugs into my home automatisation ioBroker.
So I started to compile my own EspEasy. I know I can use prebuild binaries but I like it to compile and optimize thing for my needs.

It was no problem to flash my new gosund SP211 dual plug with EspEasy but then the reverse engineering starts ...
There is a good Tasmota page to find out the pins you have to use: https://templates.blakadder.com/gosund_SP211.html
So that was my base.
I started configuring the Hardware tab with the pins. Then over to the next Tab and configure the Devices. Next was to enable rules when you need to switch with the hardware button from the SP211.
Then you have to write a rule for switching the relais and the leds. And at the end you have to setup any MQTT controller.
I use the "Home Assistant (openHAB) MQTT" controller but I discoverd very quickly that you have to use different MQTT topics for
- swiching the relais over GPIOs
- get the state of the Relais / switch

So this is a lot of work to do. And I think a beginner could easily struggle with all the settings. Coming from Tasmota it is very easy to setup such a switchable plug.
Just select a template, configure the MQTT client and you are almost done ...

So I have some changes in mind and just want to know what you guys thinking about that ...

1) Add a new device like "Input to Output"
It would be nice to have one Device where you can configure an Input and associate 2 or 3 outputs.
So basically you have 3 or 4 comboboxes. In the first you select your input pin - which is in most cases the hardware switch.
And in the rest boxes you select output pins for relais, Led, ...
If you push the button you toggle the associated outputs.
You don´t need any rules, you can see the realations between in and out and I think it´s easy to understand and easy to implement :)
@TD-er
I would love to develope this plugin. Did you see any problems I should take care about?
So would it be conflict with the internal GPIO handling if I set output pins in my plugin?

2) Add a new Controller to handle the SonOff adapter in ioBroker
The second thing I really miss is a controller to handle the SonOff Adapter in iobroker. It´s basically a MQTT broker which needs some JSON as input.
Here are some example topics:

Code: Select all

tele/sonoff/SENSOR
{"Time":"2020-09-26T14:10:35","ENERGY":{"TotalStartTime":"2019-11-16T11:49:54","Total":7.141,"Yesterday":0.000,"Today":0.000,"Period":0,"Power":0,"ApparentPower":0,"ReactivePower":0,"Factor":0.00,"Voltage":0,"Current":0.000}}
tele/sonoff/STATE
{"Time":"2020-09-26T14:11:16","Uptime":"7T08:18:19","UptimeSec":634699,"Heap":28,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":10,"POWER":"OFF","Wifi":{"AP":1,"SSId":"NoMamsLand","BSSId":"3C:A6:2F:0F:63:58","Channel":6,"RSSI":48,"LinkCount":5,"Downtime":"0T00:04:26"}}
Nothing special at all, but the Sonoff Adapter in iobroker is extreamly easy to use - so use it with EspEasy would be a dream come true :ugeek:

In iobroker you see devices with SonOff like this:
Image

And the best is yet to come ... Changing the Power item (marked yellow) directly switches the device over MQTT messages.
This is extreamly useful because you can use it for controlling and state view in one item.

So writing a Controller for EspEasy which could speak the SonOff Adapter format and is able to control devices directly over the mqtt topics would be really nice.
I think I could do this too - maybe with a little help from the devs ...

3) Putting it all together ...
So if there is a new Plugin and a new controller there is one question left. It´s more a technical or developement driven question ...
How can a controller in EspEasy inform a device / plugin that there is a new MQTT message?
If you change the POWER topic within the SonOff adapter you get a response like this:

Code: Select all

tele/sonoff/POWERON
and the device answeres like this:

Code: Select all

stat/sonoff/RESULT
{"POWER":"ON"}
Are those MQTT messages handover to the plugins? It´s not really clear to me how EspEasy handles the data.
would be nice to get a little hint for this topic.

Let´s come to an end with this long message :roll:
First of all ... What to you think about my suggestions?
And secondly ... Did you see any show stopper for these topics? Anything which couldn´t or shouldn´t implement within EspEasy ?

For me it would be a challange and some fun to do the developing.
And at the end it could be easier to setup and use power plugs (not only) with ioBroker - hopefully :D

Have a nice sunday ...
Dominik
Attachments
firefox_DOFRVaJKN5.png
firefox_DOFRVaJKN5.png (109.27 KiB) Viewed 1547 times
regards
Dominik

TD-er
Core team member
Posts: 3394
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#2 Post by TD-er » 27 Sep 2020, 10:23

I think a simple plugin to immediately act on an input state by setting an output GPIO pin is indeed something we could use.
Right now the switch plugin is extremely over complicated.
So something connecting 1 (or 2) GPIO inputs via a logic port to an output GPIO is a good step to simplify something used by a lot of users.

You probably still may need some input filtering if it is connected to a physical button.
Maybe it can also be split into a plugin acting on a state (probing 10 or 50 times a sec), so it can also act on state changes made by lots of other triggers (rules/MQTT messages/etc, more on that later)

About the MQTT messages you may receive on the ESP.
That's quite obviously something we're somewhat missing in the functional blocks.

A controller receives data from a task or a command and sends it to the other end (MQTT broker/HTTP server/etc.), but when it receives data, it is upto the controller what to do with it.
For example Domoticz MQTT has some handlers in the controller code for very specific plugins like the Domoticz helper, Switch input and maybe 1 or 2 more.
The same for OpenHAB MQTT.

This means there is no generic way of receiving messages from the broker published by others.

There is the MQTT import plugin, which can read only numerical values (int/float) from subscribed topics.

This means that if you want to implement receiving MQTT messages from another platform (like ioBroker), you may need to reinvent the wheel again and add it to the code of the newly created controller.
One thing to keep in mind is that I do find lots of code duplication and it starts to bother me enough, I will spend another weekend to go over all code using that code duplication and try to merge it into some helper class (example: Both Domoticz controllers)
So you will probably find some of those in various helper classes or files with "helper" in the name.

I will now add a few more stubs to extend the predefined controllers upto C025 as we're now running out of the existing stubs (in comments) as it needs to be done on quite a few places.


About the "state" I mentioned for the "simple connect pins plugin".
A very basic use case a lot of users want to try and run into trouble trying to do is to connect a switch to a relay and keep track of it in something like Domotics but also like to change it in Domoticz.

There are several ways to make it work and some a quite complex to get it right.

The only way that always works is if you let the relay act on an internal state (e.g. a variable) and configure all possible triggers (MQTT/switch/commands/events) to set this state and generate the event to keep the pin and the state in sync.
For Domoticz you can use the Domoticz Helper, which does make things a bit more simple to do, but then you make it depending on the WiFi connection.
For an acceptable WAF (Wife Acceptance Factor) you should also be able to turn on the light while WiFi is down.
So I think your very simple idea of just connecting input to output is a bit too simple and only serves a single purpose.

That's why I mentioned to have multiple inputs possible (where 1 may be a state instead of a pin), but that may make it again quite complicated.
Maybe this "GPIO connector" should be more like a "state connector" which has a selector to either act on a pin or a state, then have some logic like "invert" and a selector for either pin or state output.
And the option to send out an event and send to controllers like any other plugin. (it then also has an output value)

This way you can still use the existing switch plugin which has debounce functionality.

User avatar
moelski
Normal user
Posts: 161
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#3 Post by moelski » 27 Sep 2020, 18:23

Hi !

Well let´s remember the name of the projekt EspEasy. ;) So maybe it is a good idea to start with the new plugin - but in a simple way.

In the first step I would try the following :

* Selector for one input
* Selector for 2 outputs
* React on the Input by settings the outputs
* Some basic invert Logic for the outputs
* Some basic debouncing for the inputs
The only way that always works is if you let the relay act on an internal state (e.g. a variable) and configure all possible triggers (MQTT/switch/commands/events) to set this state and generate the event to keep the pin and the state in sync.
* basic implementaion for this topic.

I think this could be a good starting point for enhancements ...
Reacting on MQTT/switch/commands/events is a good idea - especially the MQTT stuff.
But let´s keep things basic for the beginning.
You should also keep in mind that I´m not a professional C(++) developer. So it will take some time for me to dive into the EspEasy code ;)

About the controller ... Would it be possible that you create a general way of informing plugins about incoming MQTT messages?
Something like PLUGIN_SERIAL_IN or PLUGIN_UDP_IN ?
Would be very helpfull ...
regards
Dominik

TD-er
Core team member
Posts: 3394
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#4 Post by TD-er » 27 Sep 2020, 20:23

Well it would be nice to have a very generic way, but it practice it is still quite platform dependent regarding format of the messages being published.
For example, is it JSON formatted, publishing in a specific topic, etc.

But let's start with the "GPIO-link-plugin" or whatever it should be called :)

User avatar
moelski
Normal user
Posts: 161
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#5 Post by moelski » 28 Sep 2020, 13:02

One question ...
If I send a command like

Code: Select all

GPIO, 10,1
... Is there a way to receive that within a plugin?
regards
Dominik

TD-er
Core team member
Posts: 3394
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#6 Post by TD-er » 28 Sep 2020, 13:26

It is perhaps more elegant to not send a command directly but send an event with the proper parameters and handle it in the rules.
When handling the event, one of the commands from the rules can then be to send the GPIO command.

For example sending

Code: Select all

event,EventName=15,1
Where "EventName" is the name you make up yourself (make sure to only use letters in the eventname, no -, + etc)
The first value (%eventvalue1% is 15 here) is used here as the GPIO pin.
The 2nd value is the state to set to the GPIO pin.

You can use upto 4 eventvalues.

In the rules:

Code: Select all

on EventName do
  gpio,%eventvalue1%,%eventvalue2%
  // Do something else you want to do
endon

User avatar
moelski
Normal user
Posts: 161
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#7 Post by moelski » 28 Sep 2020, 13:37

No you got me wrong.

I don´t want to use any rules for this plugin.

The question was about getting data from an Command ...
In the tab tools I can enter a command with something like GPIO,15,1 which will switch GPIO 15.
Will this command handed over to the plugins? So I could react on those events.

It´s just for testing ...
regards
Dominik

TD-er
Core team member
Posts: 3394
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#8 Post by TD-er » 28 Sep 2020, 14:20

There is a subtle difference between an event and a command.

A command is dealt with by either ESPEasy's internals (e.g. "GPIO" is an internal command, not one of a plugin) or by a plugin.

So sending "GPIO" as command is not being dealt with by any plugin, as it is an internal command.

There is also the command "event" which does send an event.
An event is dealt with from the rules and it is the only way to trigger an action in the rules.
A task (an instance of a plugin) may also send out an event. For example when a task has successfully read a new set of values, it will send out an event with those values along with it.
The "event name" is then something like "bme#Humidity" where "bme" is the task name and "Humidity" is the variablename.


So to get back to your question, no there is no way to get data from a command, as a command is dealt with by either the internal command handler or the plugin and the data is immediately dealt with.
You could send data in a variable via the "let" command and this variable can be used in other plugins like the display plugin (or wherever you may use system variables)

For example:

Code: Select all

let,1,123
This does set the internal variable #1 and can be referred to as [var#1]

I think that's the only thing I can think of that comes close to what you're asking.

User avatar
moelski
Normal user
Posts: 161
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#9 Post by moelski » 29 Sep 2020, 11:48

Ok I come closer with the new Plugin ...

I called it In2Out 8-)

But I need to test it the next days ... Will see if it works :D
Attachments
firefox_Ig1PwcACwP.png
firefox_Ig1PwcACwP.png (17.84 KiB) Viewed 1452 times
regards
Dominik

TD-er
Core team member
Posts: 3394
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#10 Post by TD-er » 29 Sep 2020, 15:23

Don't test it on the pins you mention in the screenshot (unless you have an ESP8285) as GPIO 9 & 10 are connected to the flash.

User avatar
moelski
Normal user
Posts: 161
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#11 Post by moelski » 30 Sep 2020, 07:11

Hi !
Don't test it on the pins you mention in the screenshot
I Know. It was only an example.

One developing question ...
I need to store some data in variables - like the starttime of pressing the button.

What is the best way to declare these plugin variables?
Just something like

Code: Select all

long P248_PRESS_TIME = 0;

boolean Plugin_248(.....
wouldn´t be a good choice. This variable would be used for all 248 Plugin instances, right?

Using the PCONFIG_xxxx is for storing settings ...

So how can I introduce a global plugin variable which is only used within the plugin instance?
regards
Dominik

TD-er
Core team member
Posts: 3394
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#12 Post by TD-er » 30 Sep 2020, 09:27

Please have a look at just about any I2C plugin. (and some others as well)
They all use a struct to keep task specific data.
The PluginStructs are stored in the src/PluginStructs directory, so there you can easily see which plugins do support this technique.

There is a global array of "PluginTaskData_base pointers" , which can be accessed via functions like getPluginTaskData and initPluginTaskData
This array is accessed via the taskindex and can store task specific data for the active plugin.

The data struct must inherit from PluginTaskData_base.

P006_BMP085.ino does seem to be the most clean example using this.

User avatar
moelski
Normal user
Posts: 161
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#13 Post by moelski » 30 Sep 2020, 09:33

Thx. I will have a look.
Hopefully I can get the plugin working tomorrow. 8-)
regards
Dominik

martinus
Normal user
Posts: 101
Joined: 15 Feb 2020, 16:57

Re: Making EspEasy a little bit more useable with ioBroker

#14 Post by martinus » 30 Sep 2020, 10:36

I've also been working on a dedicated smartplug plugin in combination with Node-Red and MQTT, see this topic:
viewtopic.php?f=6&t=7635&p=43977#p43977
It makes life easier and no rules needed. But i also had to tweak ESPEasy MQTT C005 controller to get it working as i wanted it to work.

IMHO the current MQTT support in ESPEasy is still quite basic and i enhanced it to support MQTT topics like #/<taskname>/Set to control the named task.
And also support parsing json into a plain rules value, so i can send simple json data to the ESP and it will be able to process rules on it.

But again, this has been tailored to suit my personal Node-Red environment and it's not a one solution fits all...

I guess it would require some really clever design to make a truly universal smartplug plugin that works with all mainstream systems.
Looks like TASMOTA is ahead of us on this matter but i haven't really investigated their solution.

User avatar
moelski
Normal user
Posts: 161
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#15 Post by moelski » 30 Sep 2020, 11:10

Hi !

You are right ... Tasmaota has some advantages in this area ...
But in my opinion EspEasy needs 3 modifications to make the gap to tasmo smaller ...

1) Easy Plugin for basic IO handling
That´s what I´m working on ... A simple plugin where you can define the input, the output(s) and that´s it.
Using rules and other fancy stuff for just switching a relais is to complicated :-)

2) Better MQTT support
I´m not really familar with this topic right know regarding EspEasy. But what I saw and tested was to complicated, too.
You have to use different topics for getting the state and switching a GPIO ...
I will do some investigation on this after my plugin is done ...

3) Add a simple switch botton to the UI
That´s a topic I missed in my first post here ... In Tasmota there is a simple ON / OFF Button (beside the measured values) on the first webpage.
So you enter the URL to your browser and can switch the plug immediately. I used this feature often.
See some RSSI, IP, RAM values at the first page is nice, but didn´t help alot. In my opinion this is more a page which could be called "status".

Anyway ... I´m on my developement way with the In2Out plugin. When I´m done the MQTT topic is the next part.
I would love to see support for the Sonoff Adapter from ioBroker - which is a MQTT broker at it´s base, too.
regards
Dominik

TD-er
Core team member
Posts: 3394
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#16 Post by TD-er » 30 Sep 2020, 12:41

@Martinus:
You can use any system variable in topics too.
Just use something like this: %sysname%/%tskname%/%valname%
Which is the default by the way when you add a new instance of the Home Assistant (openHAB) MQTT (C005)

martinus
Normal user
Posts: 101
Joined: 15 Feb 2020, 16:57

Re: Making EspEasy a little bit more useable with ioBroker

#17 Post by martinus » 30 Sep 2020, 15:08

TD-er wrote: 30 Sep 2020, 12:41 @Martinus:
You can use any system variable in topics too.
Just use something like this: %sysname%/%tskname%/%valname%
Which is the default by the way when you add a new instance of the Home Assistant (openHAB) MQTT (C005)
I know, it was there from the beginning. But AFAIK you still have to use ../gpio or ../cmd for ESPEasy to trigger something.
What i've explored is a way to 'catch' the taskname from a topic, look for the task that has this name and send a WRITE message to this specific task.
So you can send things like:
Demo/KitchenSwitch/Set with a payload of 0/1
Demo/LivingRoomSwitch/Set with a payload of 0/1
I think this is the most straightforward way to work with simple MQTT topics/payloads that are also human friendly to read.
AFAIK you cannot accomplish this with stock firmware, am i right?

martinus
Normal user
Posts: 101
Joined: 15 Feb 2020, 16:57

Re: Making EspEasy a little bit more useable with ioBroker

#18 Post by martinus » 30 Sep 2020, 15:15

moelski wrote: 30 Sep 2020, 11:10
3) Add a simple switch botton to the UI
That´s a topic I missed in my first post here ... In Tasmota there is a simple ON / OFF Button (beside the measured values) on the first webpage.
So you enter the URL to your browser and can switch the plug immediately. I used this feature often.
See some RSSI, IP, RAM values at the first page is nice, but didn´t help alot. In my opinion this is more a page which could be called "status".
I have used the ESPEasy mini dashboard feature for local gui buttons
https://www.letscontrolit.com/wiki/inde ... _Dashboard
also look here:
viewtopic.php?f=4&t=7946&p=46856&hilit= ... ard#p46856

To make this a home page, i think a config setting could be made in ESPEasy to load a given *.esp page as home page and use something like /home for the original home page?

TD-er
Core team member
Posts: 3394
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#19 Post by TD-er » 30 Sep 2020, 15:36

martinus wrote: 30 Sep 2020, 15:08
TD-er wrote: 30 Sep 2020, 12:41 @Martinus:
You can use any system variable in topics too.
Just use something like this: %sysname%/%tskname%/%valname%
Which is the default by the way when you add a new instance of the Home Assistant (openHAB) MQTT (C005)
I know, it was there from the beginning. But AFAIK you still have to use ../gpio or ../cmd for ESPEasy to trigger something.
What i've explored is a way to 'catch' the taskname from a topic, look for the task that has this name and send a WRITE message to this specific task.
So you can send things like:
Demo/KitchenSwitch/Set with a payload of 0/1
Demo/LivingRoomSwitch/Set with a payload of 0/1
I think this is the most straightforward way to work with simple MQTT topics/payloads that are also human friendly to read.
AFAIK you cannot accomplish this with stock firmware, am i right?
If you're talking about publish to a topic, then it is for sure possible to do so.
Can be done from the controller and from the rules.

If you're talking about receiving (subscribing), then it is not possible right now.
It would be a really nice feature, along with task addressable commands (open PR right now)

TD-er
Core team member
Posts: 3394
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#20 Post by TD-er » 30 Sep 2020, 15:37

martinus wrote: 30 Sep 2020, 15:15
moelski wrote: 30 Sep 2020, 11:10
3) Add a simple switch botton to the UI
That´s a topic I missed in my first post here ... In Tasmota there is a simple ON / OFF Button (beside the measured values) on the first webpage.
So you enter the URL to your browser and can switch the plug immediately. I used this feature often.
See some RSSI, IP, RAM values at the first page is nice, but didn´t help alot. In my opinion this is more a page which could be called "status".
I have used the ESPEasy mini dashboard feature for local gui buttons
https://www.letscontrolit.com/wiki/inde ... _Dashboard
also look here:
viewtopic.php?f=4&t=7946&p=46856&hilit= ... ard#p46856

To make this a home page, i think a config setting could be made in ESPEasy to load a given *.esp page as home page and use something like /home for the original home page?
There should be some code present to check for the existence of some file on the file system.
This way you should be able to apply some redirect I guess?

User avatar
moelski
Normal user
Posts: 161
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#21 Post by moelski » 01 Oct 2020, 06:47

@TD-er
Another dev releated question ...

Can I check details for the CONFIG_PIN1 ... PIN3 configuration like the selected type (input pulldown, ....) from the hardware page?

Ok and one question about the data struct for plugins ...
This code works like a charme ... A simple toggle function (all vars are just bool):

Code: Select all

            // read Button State ...
            ActInput248 = digitalRead(CONFIG_PIN1);
            ActInput248 = !ActInput248;

            if (ActInput248 == 1) {
              if (LastInput248 != ActInput248) {     // P248_data->check()) {
                Toggle248 = !Toggle248;
              }
            }

            LastInput248 = ActInput248;
But convert it to the datastruct version:

Code: Select all

        initPluginTaskData(event->TaskIndex, new (std::nothrow) P248_data_struct());
        P248_data_struct *P248_data = static_cast<P248_data_struct *>(getPluginTaskData(event->TaskIndex));
        if (nullptr != P248_data) {
            // read Button State ...
            P248_data->ActInput = digitalRead(CONFIG_PIN1);
            P248_data->ActInput = !P248_data->ActInput;

            if (P248_data->ActInput == 1) {
              if (P248_data->ActInput  != P248_data->LastInput) {
                P248_data->Toggle = !P248_data->Toggle;
              }
            }
            P248_data->LastInput = P248_data->ActInput;
          }
... things gettings strange ...
The inner if is always true :o
And to be honest ... I have no idea why. Did I miss some castings or something else here ?

The data struct is basically this:

Code: Select all

struct P248_data_struct : public PluginTaskData_base {
  bool  	Toggle;
  bool 		LastInput;
  bool 		ActInput;
};
regards
Dominik

User avatar
moelski
Normal user
Posts: 161
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#22 Post by moelski » 01 Oct 2020, 10:52

Oh Man ... I´m stupid ...
I always called the init part again :roll:

Code: Select all

initPluginTaskData(event->TaskIndex, new (std::nothrow) P248_data_struct());
*face palm*
regards
Dominik

martinus
Normal user
Posts: 101
Joined: 15 Feb 2020, 16:57

Re: Making EspEasy a little bit more useable with ioBroker

#23 Post by martinus » 01 Oct 2020, 11:41

moelski wrote: 01 Oct 2020, 10:52 Oh Man ... I´m stupid ...
Everyone is allowed to be stupid once a month :lol:
If the frequency increases, you may have to start worrying...

TD-er
Core team member
Posts: 3394
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#24 Post by TD-er » 01 Oct 2020, 13:04

martinus wrote: 01 Oct 2020, 11:41
moelski wrote: 01 Oct 2020, 10:52 Oh Man ... I´m stupid ...
Everyone is allowed to be stupid once a month :lol:
If the frequency increases, you may have to start worrying...
... as you may be learning a lot then :)

User avatar
moelski
Normal user
Posts: 161
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#25 Post by moelski » 01 Oct 2020, 13:08

@TD-er
Another dev releated question ...

Can I check details for the CONFIG_PIN1 ... PIN3 configuration like the selected type (input pulldown, ....) from the hardware page?
regards
Dominik

TD-er
Core team member
Posts: 3394
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#26 Post by TD-er » 01 Oct 2020, 13:13

Well not entirely sure what you mean here, as CONFIG_PIN1 is a macro to directly access the settings based on the event you're processing.
So it refers to a GPIO number, based on a taskindex.

What you can do, is enable pin monitoring
See the documentation (example: https://espeasy.readthedocs.io/en/lates ... r#commands )

User avatar
moelski
Normal user
Posts: 161
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#27 Post by moelski » 01 Oct 2020, 13:19

Ok I will explain it in antoher way :-)

Let´s say CONFIG_PIN1 results 18 for GPIO18. Can I check the settings for GPIO 18 made on the hardware tab?
GPIO 18 is used as input pin in my config. So I would like to check if it is set to INPUT.
And which kind of Input (pullup or pulldown).

So I can prevent the plugin from switching or reading missconfigured pins.
regards
Dominik

TD-er
Core team member
Posts: 3394
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#28 Post by TD-er » 01 Oct 2020, 16:42

The selection on the "hardware" tab is about the boot state of the GPIO.
This means the ESP will actively set the pull-up (or pull down) resistors as soon as the settings file is active, before any task or controller is started.

This allows to use an internal pull-up resistor (on ESP32 also pull-down and GPIO16 on the ESP82xx) which may be needed for proper operations of the connected sensor.
But it may be desired to not have an external resistor to make sure no extra current is drawn while the sensor is in sleep mode. Or simply because no resistor is added while some is needed for proper operations.

So it is a setting to enable a pull-up resistor at boot.
It has nothing to do with the settings of tasks.

You may have some pull-up checkbox for some plugins, but that's another bit in the settings file.
What is shown on the Hardware tab is just a flag of how to set the pull-up resistors at boot.

User avatar
moelski
Normal user
Posts: 161
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#29 Post by moelski » 03 Oct 2020, 07:05

My actual status ...

1) Easy Plugin for basic IO handling
I think this is mostly done. It runs as it should :) I will try it on a Sonoff in the next days.
firefox_BUXMkDGq15.png
firefox_BUXMkDGq15.png (19.95 KiB) Viewed 1306 times
Maybe I add an option for delayed off. But at the moment it´s not needed ...

2) Better MQTT support
This is also mostly done ... But I need a little help so please see my question beyond.
firefox_0Qp1cC3J0w.png
firefox_0Qp1cC3J0w.png (66.44 KiB) Viewed 1303 times
I wrote a new controller which handles the MQTT publishing for the ioBroker Sonoff Adapter.
It´s tested with 4 devices configured in EspEasy and it seems to run fine 8-)

3) Add a simple switch botton to the UI
Not covered yet ...
But maybe it´s a solution to use the mini dashboard feature for this purpose ... We will see ..

Ok but here is my dev question about the controller ...
Is there a way to loop over all configured devices and get the Pluginname or the Pluginnumber?

Code: Select all

#define PLUGIN_ID_248     248           // plugin id      <<<<<<
#define PLUGIN_NAME_248   "In2Out"      // Plugin Name    <<<<<<
Here is the background for that question ...
If I configure my new Plugin In2Out I need to add some additional states to the MQTT message called "POWER".
But I need to check if there are plugins configured with the Name "In2Out" or with the Plugin ID 248 and how many are configured.
In pseudo code something like this ...

Code: Select all

        int count = 0;
        for (byte x = 0; x < Devicecount; x++){
          if (Device[x].PluginNr == 248) {
            count++;
          }
        }
regards
Dominik

martinus
Normal user
Posts: 101
Joined: 15 Feb 2020, 16:57

Re: Making EspEasy a little bit more useable with ioBroker

#30 Post by martinus » 03 Oct 2020, 10:57

moelski wrote: 03 Oct 2020, 07:05 But I need to check if there are plugins configured with the Name "In2Out" or with the Plugin ID 248 and how many are configured.
For my smartplug (p240), I use this to check which tasks are configured for this plugin and it also checks the task by name, because multiple tasks could be defined:

Code: Select all

    case PLUGIN_WRITE:
      {
        String cmd = parseString(string, 1);

        if (cmd.equalsIgnoreCase(F("SmartPlug")))
        {
          success = true;
          String taskName = parseString(string, 2);
          byte state = parseString(string, 3).toInt();

          for (taskIndex_t task = 0; task < TASKS_MAX; task++) {
            if (Settings.TaskDeviceNumber[task] == PLUGIN_ID_240) {
              LoadTaskSettings(task);
              if (taskName.equalsIgnoreCase(ExtraTaskSettings.TaskDeviceName)) {
                P240_switch(state, event);
              }
            }
          }
        }
You can control it like this:
smartplug <taskname>,0|1

User avatar
moelski
Normal user
Posts: 161
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#31 Post by moelski » 03 Oct 2020, 11:42

Hi martinus,

Will have a look. Thx so far.
regards
Dominik

TD-er
Core team member
Posts: 3394
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#32 Post by TD-er » 03 Oct 2020, 12:23

Some plugins can have a selection to act on some plugin, like the level plugin.
There is an example of how to add a selector containing all active tasks.

User avatar
moelski
Normal user
Posts: 161
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#33 Post by moelski » 06 Oct 2020, 08:35

Ok, I got my stuff working so far.
But there is one question left ...

The MQTT messages will only be send if the plugin does a read.
Is it possible to trigger a MQTT send event?

If I press the button at my power plug it will be recognised by the PLUGIN_FIFTY_PER_SECOND event.
But sending the changed data/state to MQTT could be seconds later.
It would be great to fire a MQTT send event if the state of my plugin has changed.
Any chance to do this right now?
regards
Dominik

User avatar
Ath
Normal user
Posts: 244
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Making EspEasy a little bit more useable with ioBroker

#34 Post by Ath » 06 Oct 2020, 08:58

You could issue a TaskValueRun command from the rules (if you are using rules), or schedule a timer (there are examples available in other plugins, but I don't have them at hand right now)
/Ton

User avatar
moelski
Normal user
Posts: 161
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#35 Post by moelski » 06 Oct 2020, 09:03

Hi Ath,

I try to don´t use rules. That makes the initial setup to complicated.
schedule a timer
Would be much easier to just fire some kind of event when the value changed.
Having an extra timer sounds a little bit overkill for this task :roll:
regards
Dominik

User avatar
Ath
Normal user
Posts: 244
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Making EspEasy a little bit more useable with ioBroker

#36 Post by Ath » 06 Oct 2020, 09:15

Well, I've seen TD-er suggest starting a timer as the solution a couple of times, this is copied from the PLUGIN_ONCE_A_SECOND event of P028:

Code: Select all

        if (P028_data->updateMeasurements(tempOffset, event->TaskIndex)) {
          // Update was succesfull, schedule a read.
          Scheduler.schedule_task_device_timer(event->TaskIndex, millis() + 10);
        }
The comment speaks for itself, I think, and the schedule_task_device_timer is specifically 'reserved' for this job.
/Ton

User avatar
moelski
Normal user
Posts: 161
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#37 Post by moelski » 06 Oct 2020, 09:31

Ok I will try it. Thx
regards
Dominik

User avatar
moelski
Normal user
Posts: 161
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Making EspEasy a little bit more useable with ioBroker

#38 Post by moelski » 06 Oct 2020, 09:55

First test works like a charme. :)
regards
Dominik

Post Reply

Who is online

Users browsing this forum: No registered users and 30 guests