PCF8574 IO Switch by MQTT
Moderators: grovkillen, Stuntteam, TD-er
PCF8574 IO Switch by MQTT
Hi
just installed my D1 mini with an PCF8574 and this ESP (GPIOs) and PCF (PINs) are fully equipped so would be great to find a solution.
6 of the Pins from the PCF are conntected to LEDs and I like to switch these LEDs directly by MQTT in IOBroker.
For the GPIOs I´ve learned to build a dedicated structure in iobroker to switch the GPIOs directly.
Now I adapted this solution for the PCFGPIOs but the LEDs are not working. Does anybody has expierence how to do that?
2 Switches which are also connected to the PCF (PIN 3 & 6) are working fine. The LEDs are connected to 3.3V and the Cathode is connected to the PIN (including resistor) to make the PCF handle the current.
Because the LEDs are not Setup AS devices in espeasy i think i cannot configure anything, right?
Thx in advance.
just installed my D1 mini with an PCF8574 and this ESP (GPIOs) and PCF (PINs) are fully equipped so would be great to find a solution.
6 of the Pins from the PCF are conntected to LEDs and I like to switch these LEDs directly by MQTT in IOBroker.
For the GPIOs I´ve learned to build a dedicated structure in iobroker to switch the GPIOs directly.
Now I adapted this solution for the PCFGPIOs but the LEDs are not working. Does anybody has expierence how to do that?
2 Switches which are also connected to the PCF (PIN 3 & 6) are working fine. The LEDs are connected to 3.3V and the Cathode is connected to the PIN (including resistor) to make the PCF handle the current.
Because the LEDs are not Setup AS devices in espeasy i think i cannot configure anything, right?
Thx in advance.
- Attachments
-
- PCF.JPG (47.37 KiB) Viewed 13708 times
Re: PCF8574 IO Switch by MQTT
Can you turn the LED's on & off from the Tools page of ESPEasy, using the matching 'pcfgpio,<port>,<0|1>' commands?
/Ton (PayPal.me)
Re: PCF8574 IO Switch by MQTT
So far I could not find/get a working solution over MQTT so started to switch the PCFGPIOs by http command:
http://<ESP IP address>/control?cmd=pcfgpio,1,0/1
This works but what I´m missing is the feedback and status information of each PCFGPIO.
So now I´m trying to implement by rule a publish command to send the status of each PCFGPIO in case it is changed.
In addition I think it is a good idea to define each PCFGPIO status at system boot and also publish each status to be sure & define fix states what is happening everywhere and when
Because of 6 PCFGPIOs seems to be a bigger rule and hope it can be optimzed so it will work fully stable
Or as alternative do you think adding 6 switches as devices for the 6 PCFGPIOS/LEDs is a better solution?
But I have currently 4 out of 12 devices free to use in easyesp.
I´m sure to have read a post that it´s possible to expand the max number of to devices, but I´m not sure about the effort and if this is possible for me or even recommendable...?
What would you prefer to do?
http://<ESP IP address>/control?cmd=pcfgpio,1,0/1
This works but what I´m missing is the feedback and status information of each PCFGPIO.
So now I´m trying to implement by rule a publish command to send the status of each PCFGPIO in case it is changed.
In addition I think it is a good idea to define each PCFGPIO status at system boot and also publish each status to be sure & define fix states what is happening everywhere and when
Because of 6 PCFGPIOs seems to be a bigger rule and hope it can be optimzed so it will work fully stable
Or as alternative do you think adding 6 switches as devices for the 6 PCFGPIOS/LEDs is a better solution?
But I have currently 4 out of 12 devices free to use in easyesp.
I´m sure to have read a post that it´s possible to expand the max number of to devices, but I´m not sure about the effort and if this is possible for me or even recommendable...?
What would you prefer to do?
Re: PCF8574 IO Switch by MQTT
Well it is indeed possible to extend the number of tasks to 24.
But having 24 tasks defined also has an impact on resource usage (although I'm trying to lower that demand)
But having 24 tasks defined also has an impact on resource usage (although I'm trying to lower that demand)
Re: PCF8574 IO Switch by MQTT
Rather than going into 'experimental teritory', you could buy an ESP32 dev board. It has way more useable GPIOs, is much faster than an ESP8266, and ESPEasy is configured by default to have 32 devices.
Price shouldn't be a problem as you can find these boards for around $6 on Aliexpress, or around €10 - €15 from local EU resellers (those that buy wholesale from Ali , and usually have a shorter delivery time, as they tend to have them in stock)
/Ton (PayPal.me)
Re: PCF8574 IO Switch by MQTT
Thx, this would be a non standard solution and e.g. everytime I´m doing an update of easyesp this means additional work or even problems.
Because my housing is very crowded and also the Dupont cables are not getting better by touching them to often (already had some connection problems) my intention is not to expand this solution further in the future (don´t touch a running system). So 4 devices free out of 12 means 2 additional devices are needed. Is it necessary to expand an non-standard solution to 24 or can it be limited to 14 ? The CPU usage is at 11%. Think the non-standard solution has to be considered much more than reaching limits by this, right?
Re: PCF8574 IO Switch by MQTT
Thx for your feedback. By having the PCF8574 connection problems I already recognized that an ESP32 might be worth to think about because it woul be one piece of hardware without an additional interface to connect IOs for my solution. Have seen D1 Mini equivalents of ESP32 at Ali-Express for 2€ so the time for delivery as mentioned by you and for fully replace the exiting solution is more considerable for me.Ath wrote: ↑13 Sep 2020, 10:32Rather than going into 'experimental teritory', you could buy an ESP32 dev board. It has way more useable GPIOs, is much faster than an ESP8266, and ESPEasy is configured by default to have 32 devices.
Price shouldn't be a problem as you can find these boards for around $6 on Aliexpress, or around €10 - €15 from local EU resellers (those that buy wholesale from Ali , and usually have a shorter delivery time, as they tend to have them in stock)
Also as mentioned before, the connection e..g. Dupont cables are not getting better by touching them to often so also a risk some cables for reuse will not work anymore.
So after this weekend with many connections problem by cables caused by a full housing and many dismounts to replace the resistors of the LEDs to adjust the brightness to a acceptable level I am very happy the "hardware" part seems to be at very mature state(out of my opinion). Have to sleep one night and rethink also taking your points into account what would be best solution for for me.
Also taking into account that by a non-standard solution with 14 devices or implementation by rules this would not be your favorite and maybe without a helping hint of you two I would get anything into operation
- Attachments
-
- IMG_20200912_191130.jpg (213.04 KiB) Viewed 13644 times
Last edited by Oetsch on 13 Sep 2020, 12:16, edited 2 times in total.
Re: PCF8574 IO Switch by MQTT
Well regardless of changing it to 14 or 24, it would mean incompatible settings.
And running at 24 tasks without using them is not going to take a lot of extra resources.
My warning was more about if you increase the number of tasks, you are likely to use them and with more active tasks, you would consume more resources like RAM.
And running at 24 tasks without using them is not going to take a lot of extra resources.
My warning was more about if you increase the number of tasks, you are likely to use them and with more active tasks, you would consume more resources like RAM.
Re: PCF8574 IO Switch by MQTT
Thx, taking Ath´s suggestion under consideration. Is the ESP32 version of ESPEASY also limited to 12 devices by default?TD-er wrote: ↑13 Sep 2020, 12:12 Well regardless of changing it to 14 or 24, it would mean incompatible settings.
And running at 24 tasks without using them is not going to take a lot of extra resources.
My warning was more about if you increase the number of tasks, you are likely to use them and with more active tasks, you would consume more resources like RAM.
- Attachments
-
- ram.JPG (47.79 KiB) Viewed 13643 times
Re: PCF8574 IO Switch by MQTT
Nope, the ESP32 build has 32 tasks
Re: PCF8574 IO Switch by MQTT
Thx sounds good but have to think about it.
Based on my personal experience i think i will order a ESP32 und during delivery time i´ll test and make it work by rules
Non-standard solution is not the right way for me i think.
Based on my personal experience i think i will order a ESP32 und during delivery time i´ll test and make it work by rules
Non-standard solution is not the right way for me i think.
Re: PCF8574 IO Switch by MQTT
Sorry to ask again and please let me understand that this is not a recommanded solution?
The PCF Plugin seems to be adjusted since Aug 2018 for PCFGPIO monitoring or missunderstood by me?
Found this example with github discussion (publish command was added by me):
The PCF Plugin seems to be adjusted since Aug 2018 for PCFGPIO monitoring or missunderstood by me?
Found this example with github discussion (publish command was added by me):
Code: Select all
on System#Boot do
Monitor,PCFGPIO,0
endon
on pcfGPIO#0=1 do
if [Plugin#pcfGPIO#Pinstate#1]=1
Publish %sysname%/PCFGPIO/0,[Plugin#pcfGPIO#Pinstate#1]
endif
endon
on pcfGPIO#0=0 do
if [Plugin#pcfGPIO#Pinstate#1]=0
Publish %sysname%/PCFGPIO/0,[Plugin#pcfGPIO#Pinstate#1]
endif
endon
Re: PCF8574 IO Switch by MQTT
Not sure whether it is a good idea at all, but at least I would suggest not to use multiple blocks acting on the same event only with different event values.
So to just tackle that part:
And maybe you should also not use variable names only containing numbers, but I'm not sure that will cause an issue. Just a hunch.
So to just tackle that part:
Code: Select all
on pcfGPIO#0 do
if [Plugin#pcfGPIO#Pinstate#1]=%eventvalue%
Publish %sysname%/PCFGPIO/0,[Plugin#pcfGPIO#Pinstate#1]
endif
endon
Re: PCF8574 IO Switch by MQTT
Thank you very much. Based on your code did some testing and found the syntax to make it work.
This is now running and working for all 6 LEDs connected to the PCF8574.
Think I will change the values / turn the logik 0=true and 1=false because of sink connection inside of iobroker.
This is now running and working for all 6 LEDs connected to the PCF8574.
Think I will change the values / turn the logik 0=true and 1=false because of sink connection inside of iobroker.
Code: Select all
on System#Boot do
Monitor,pcf,1
Monitor,pcf,2
Monitor,pcf,4
Monitor,pcf,5
Monitor,pcf,7
Monitor,pcf,8
endon
on pcf#1 do
Publish,%sysname%/PCFGPIO/P1Gruen,[plugin#pcfgpio#pinstate#1]
endon
on pcf#2 do
Publish,%sysname%/PCFGPIO/P2Rot,[plugin#pcfgpio#pinstate#2]
endon
on pcf#4 do
Publish,%sysname%/PCFGPIO/P4BlauET1,[plugin#pcfgpio#pinstate#4]
endon
on pcf#5 do
Publish,%sysname%/PCFGPIO/P5BlauET2,[plugin#pcfgpio#pinstate#5]
endon
on pcf#7 do
Publish,%sysname%/PCFGPIO/P7GelbAT1,[plugin#pcfgpio#pinstate#7]
endon
on pcf#8 do
Publish,%sysname%/PCFGPIO/P8GelbAGarten,[plugin#pcfgpio#pinstate#8]
endon
Re: PCF8574 IO Switch by MQTT
Hmm, I just looked for the transformations syntax in the docs: https://espeasy.readthedocs.io/en/lates ... red-values
But apparently there is none to output "true" and "false"
Very odd...
But apparently there is none to output "true" and "false"
Very odd...
Re: PCF8574 IO Switch by MQTT
I'm using a PCF8574A to control a relay board. I only need 3 relays so I use the ports 65, 66 and 68.
To display each port status I use the Switch input - PCF8574 device type. The motor has 2 speeds, port 65 and 66 turns on the motor, port 68 is for high speed.
To log if the motor is running or not, or if it's running at high speed I have the following rule to send 0 for OFF, 1 for On and 2 for HIGH to a dummy device:
I don't know if it solves you problem, but I hope it helpes.
To send the command to the esp unit I use openhab mqtt. Here is the thing/ item configuration for openhab:
Code: Select all
Thing mqtt:topic:esp12 "04 Kitchen ventilation" @ "Kitchen" {
Channels:
Type switch : FF_Kitchen_Ventesp65 "GPIO relay" [ commandTopic="esp12/cmd", on="PCFGPIO,65,0", off="PCFGPIO,65,1" ]
Type switch : FF_Kitchen_Ventesp66 "GPIO relay" [ commandTopic="esp12/cmd", on="PCFGPIO,66,0", off="PCFGPIO,66,1" ]
Type switch : FF_Kitchen_Ventesp68 "GPIO relay" [ commandTopic="esp12/cmd", on="PCFGPIO,68,0", off="PCFGPIO,68,1" ]
}
Code: Select all
Switch FF_Kitchen_Ventesp65 "Kitchen esp13 GPIO65 Control" <none> (FF_Utilities) { channel="mqtt:topic:esp12:FF_Kitchen_Ventesp65" }
Switch FF_Kitchen_Ventesp66 "Kitchen esp13 GPIO66 Control" <none> (FF_Utilities) { channel="mqtt:topic:esp12:FF_Kitchen_Ventesp66" }
Switch FF_Kitchen_Ventesp68 "Kitchen esp13 GPIO68 Control" <none> (FF_Utilities) { channel="mqtt:topic:esp12:FF_Kitchen_Ventesp68" }
Code: Select all
on pcf8574-65#State do
if [pcf8574-65#State]=0
TaskValueSet 2,2,0
else
if [pcf8574-65#State]=1 and [pcf8574-66#State]=1 and [pcf8574-68#State]=0
TaskValueSet 2,2,1
else
TaskValueSet 2,2,2
endif
endon
on pcf8574-68#State do
if [pcf8574-65#State]=0
TaskValueSet 2,2,0
else
if [pcf8574-65#State]=1 and [pcf8574-66#State]=1 and [pcf8574-68#State]=0
TaskValueSet 2,2,1
else
TaskValueSet 2,2,2
endif
endon
Re: PCF8574 IO Switch by MQTT
Thank you very much also for the reference for me to lookup. Have also seen that in case of plugins a transformation cannot be used.TD-er wrote: ↑14 Sep 2020, 00:30 Hmm, I just looked for the transformations syntax in the docs: https://espeasy.readthedocs.io/en/lates ... red-values
But apparently there is none to output "true" and "false"
Very odd...
In general today I say not critical because I can change in iobroker but the command to switch (http) isn´t also changed yet so would like to have a unified solution (both or non are tranformed). Maybe I´ll keep it like it is.
But today I thought of the first szenario to be handled right, a reboot of the ESP). In this case I would like to set the gpios to a nutral/safe state and also communicate this states to have the right information everywhere. But these publish commands on systemboot are not executed / are not received.
Don´t know why. ESP in overload at systemboot, mqtt not ready, pcf plugin not ready?
Code: Select all
on System#Boot do
Monitor,pcf,1
Monitor,pcf,2
Monitor,pcf,4
Monitor,pcf,5
Monitor,pcf,7
Monitor,pcf,8
pcfgpio,1,1
pcfgpio,2,0
pcfgpio,4,0
pcfgpio,5,1
pcfgpio,7,1
pcfgpio,8,0
Publish,%sysname%/PCFGPIO/P1Gruen,[plugin#pcfgpio#pinstate#1]
Publish,%sysname%/PCFGPIO/P2Rot,[plugin#pcfgpio#pinstate#2]
Publish,%sysname%/PCFGPIO/P4BlauET1,[plugin#pcfgpio#pinstate#4]
Publish,%sysname%/PCFGPIO/P5BlauET2,[plugin#pcfgpio#pinstate#5]
Publish,%sysname%/PCFGPIO/P7GelbAT1,[plugin#pcfgpio#pinstate#7]
Publish,%sysname%/PCFGPIO/P8GelbAGarten,[plugin#pcfgpio#pinstate#8]
endon
Re: PCF8574 IO Switch by MQTT
Thank you very much LaurB! This MQTT information is very interesting for me. Because I´m not using Openhab as automation plattform I cannot directly adapt it but the controler of espeasy uses the openhab mqtt interface which should be same. Problem why I don´t have made it working seems to be at the iobroker configuration side.LaurB wrote: ↑14 Sep 2020, 09:24
To send the command to the esp unit I use openhab mqtt. Here is the thing/ item configuration for openhab:Code: Select all
Thing mqtt:topic:esp12 "04 Kitchen ventilation" @ "Kitchen" { Channels: Type switch : FF_Kitchen_Ventesp65 "GPIO relay" [ commandTopic="esp12/cmd", on="PCFGPIO,65,0", off="PCFGPIO,65,1" ] Type switch : FF_Kitchen_Ventesp66 "GPIO relay" [ commandTopic="esp12/cmd", on="PCFGPIO,66,0", off="PCFGPIO,66,1" ] Type switch : FF_Kitchen_Ventesp68 "GPIO relay" [ commandTopic="esp12/cmd", on="PCFGPIO,68,0", off="PCFGPIO,68,1" ] }
Code: Select all
Switch FF_Kitchen_Ventesp65 "Kitchen esp13 GPIO65 Control" <none> (FF_Utilities) { channel="mqtt:topic:esp12:FF_Kitchen_Ventesp65" } Switch FF_Kitchen_Ventesp66 "Kitchen esp13 GPIO66 Control" <none> (FF_Utilities) { channel="mqtt:topic:esp12:FF_Kitchen_Ventesp66" } Switch FF_Kitchen_Ventesp68 "Kitchen esp13 GPIO68 Control" <none> (FF_Utilities) { channel="mqtt:topic:esp12:FF_Kitchen_Ventesp68" }
Thanks but in case of ESP8266 this is hard for me to do because i do not have enough free devices to use. So without the use of devices it seems not be possible to fully work (switching & monitoring) by Mqtt, right?
Nevertheless I will review your information and check what i can learn from it. Very good Thank you very much and I´m happy to see that this similar solution works in practice (First I´ve seen from a "user").
Re: PCF8574 IO Switch by MQTT
Try and tested and this worksOetsch wrote: ↑14 Sep 2020, 09:45Thank you very much also for the reference for me to lookup. Have also seen that in case of plugins a transformation cannot be used.TD-er wrote: ↑14 Sep 2020, 00:30 Hmm, I just looked for the transformations syntax in the docs: https://espeasy.readthedocs.io/en/lates ... red-values
But apparently there is none to output "true" and "false"
Very odd...
In general today I say not critical because I can change in iobroker but the command to switch (http) isn´t also changed yet so would like to have a unified solution (both or non are tranformed). Maybe I´ll keep it like it is.
But today I thought of the first szenario to be handled right, a reboot of the ESP). In this case I would like to set the gpios to a nutral/safe state and also communicate this states to have the right information everywhere. But these publish commands on systemboot are not executed / are not received.
Don´t know why. ESP in overload at systemboot, mqtt not ready, pcf plugin not ready?
Code: Select all
on System#Boot do Monitor,pcf,1 Monitor,pcf,2 Monitor,pcf,4 Monitor,pcf,5 Monitor,pcf,7 Monitor,pcf,8 pcfgpio,1,1 pcfgpio,2,0 pcfgpio,4,0 pcfgpio,5,1 pcfgpio,7,1 pcfgpio,8,0 Publish,%sysname%/PCFGPIO/P1Gruen,[plugin#pcfgpio#pinstate#1] Publish,%sysname%/PCFGPIO/P2Rot,[plugin#pcfgpio#pinstate#2] Publish,%sysname%/PCFGPIO/P4BlauET1,[plugin#pcfgpio#pinstate#4] Publish,%sysname%/PCFGPIO/P5BlauET2,[plugin#pcfgpio#pinstate#5] Publish,%sysname%/PCFGPIO/P7GelbAT1,[plugin#pcfgpio#pinstate#7] Publish,%sysname%/PCFGPIO/P8GelbAGarten,[plugin#pcfgpio#pinstate#8] endon
Code: Select all
on System#Boot do
Monitor,pcf,1
Monitor,pcf,2
Monitor,pcf,4
Monitor,pcf,5
Monitor,pcf,7
Monitor,pcf,8
pcfgpio,1,1
pcfgpio,2,0
pcfgpio,4,0
pcfgpio,5,1
pcfgpio,7,1
pcfgpio,8,0
endon
on MQTT#Connected do
Publish,%sysname%/PCFGPIO/P1Gruen,[plugin#pcfgpio#pinstate#1]
Publish,%sysname%/PCFGPIO/P2Rot,[plugin#pcfgpio#pinstate#2]
Publish,%sysname%/PCFGPIO/P4BlauET1,[plugin#pcfgpio#pinstate#4]
Publish,%sysname%/PCFGPIO/P5BlauET2,[plugin#pcfgpio#pinstate#5]
Publish,%sysname%/PCFGPIO/P7GelbAT1,[plugin#pcfgpio#pinstate#7]
Publish,%sysname%/PCFGPIO/P8GelbAGarten,[plugin#pcfgpio#pinstate#8]
endon
Re: PCF8574 IO Switch by MQTT
I'm glad it works.
I have tryed to replicate your setup, if I understood correctly. I used one D1 and an 8 relay board.
For this test I used http command PCFGPIO,<pin>,<value> to control the relays, for a real project I would have used openhab-mqtt.
To monitor the relays I used 8 tasks.
Of course you can also send the status of any pin by mqtt.
I'm very sloppy with rules so I didn't used any. Is this what you where trying to achieve?
I have tryed to replicate your setup, if I understood correctly. I used one D1 and an 8 relay board.
For this test I used http command PCFGPIO,<pin>,<value> to control the relays, for a real project I would have used openhab-mqtt.
To monitor the relays I used 8 tasks.
Of course you can also send the status of any pin by mqtt.
I'm very sloppy with rules so I didn't used any. Is this what you where trying to achieve?
Re: PCF8574 IO Switch by MQTT
Oh what an effort, thx! Yes this is the adapted setup but in addition I use 1x MAX7219 Display, 1x RCW-0001 Ultrasonic Sensor, 1x 3-Wire DS18B20 and 4x Push Buttons at the same ESP8266. So really equipped it to an economic level
"Problem" which talked about with TD-er before ist that already 8 devices are in use of the ESPEASY software and even if it´s possible to expand the maximum number over 12 I do not like because it´s non standard and TD-er do not recommend. So tried to solve it by rules. OK, also not everybodies favorite solution and replacement of ESP8266 to ESP32 was discussed but currently it works and I´m happy to go on. Will see what I´ll do in the future (tank 2 isn´t equipped with an ultrasonic sensor so maybe an option to replace with esp32)
"Problem" which talked about with TD-er before ist that already 8 devices are in use of the ESPEASY software and even if it´s possible to expand the maximum number over 12 I do not like because it´s non standard and TD-er do not recommend. So tried to solve it by rules. OK, also not everybodies favorite solution and replacement of ESP8266 to ESP32 was discussed but currently it works and I´m happy to go on. Will see what I´ll do in the future (tank 2 isn´t equipped with an ultrasonic sensor so maybe an option to replace with esp32)
- Attachments
-
- devices.JPG (135.5 KiB) Viewed 13555 times
Who is online
Users browsing this forum: Ahrefs [Bot] and 122 guests