Added i/o with PCF8574 but not working with mqtt?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
BounceMeister
Normal user
Posts: 10
Joined: 10 Mar 2017, 20:25

Added i/o with PCF8574 but not working with mqtt?

#1 Post by BounceMeister » 11 Jul 2021, 12:27

I have been using esp-easy for a while now, slowly expanding throughout diy projects around the house and the swimmingpool.

I have a Wemos D1 (ESP8266) which does not have much i/o, so i added a PCF8574 i/o expander.
This needs to be connected to Domiticz via MQTT (mosquitto).
(Eventually there will be 4 buttons and 4 leds, oled and relay connected to this, if the amount of tasks allow it.
There will be more devices like this controlling the same switches and temperatures in Domoticz, that's why i am trying to use mqtt to set this up, to avoid having to send multiple http commands from each device to keep the rest updated.)

What i have now as a test setup:
For one pushbutton/led combo, i use two tasks:
1. A pushbutton connected to port 1 on the PCF8574, this can only be configured as normal switch in espeasy.
2. A led connected to port 2 of the PCF8574 to indicate visually and to use as status for linking to Domoticz (since the pushbutton cannot do this on the PCF).

To switch the status using the pushbutton, i made this script:

Code: Select all

// Knop1
on PCF1Button1#State=1 do  // Pushbutton pressed
  if [PCF1Led2#State]=0   //If led is off then
    PCFGPIO,2,0   // Switch on led (inversed logic)
  else
    PCFGPIO,2,1  // Else switch off led (inversed logic)
  endif
endon
This works:
I press the pushbutton, PCF1Poort1 becomes 0, the event is triggered and it changes the state of PCF1Led2, then i release the button and PCF1Poort1 becomes 1 again. The led does not change state until i press the button again. This is ok.
This ESP is linked to "Domoticz MQTT" and i added/linked the IDX (idx = 14) to PCF1Led2 on the device/task page of PCF1Led2. This is updated nicely in Domoticz when i press the pushbutton.
But when i click the switch in Domoticz, the led on the ESP is not responding.
I tried finding a solution to this, but the info is a bit confusing, maybe due to older versions used in the info i found.

Do i need to sacrifice a task for a "Generic - MQTT Import" device? I tried linking it to the Domoticz/out/$14 but it does not respond.
Then i figured it might be the other way around and i had to use the "Output - Domoticz MQTT Helper" device, but this can only be linked to general GPIO devices, which i cannot use because there are not enough of them.
Is there any way to make this work?
Also, how would i import temperature sensors from domoticz mqtt into this esp?

Firmware: 20113 - Mega

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

Re: Added i/o with PCF8574 but not working with mqtt?

#2 Post by TD-er » 11 Jul 2021, 12:48

MQTT is indeed preferred over HTTP, since it does keep a connection open instead of creating a new connection for every update.

The Domoticz controller does support some commands and some direct interactions to GPIO (in combination with the Domoticz Helper, see documentation page for this)
However this combination does not (yet) work with GPIOs on GPIO expanders like the PCF.

So for now I don't see a way to fix this for the expander. Maybe someone else does have a better idea for this?

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

Re: Added i/o with PCF8574 but not working with mqtt?

#3 Post by Ath » 11 Jul 2021, 12:55

TD-er wrote: 11 Jul 2021, 12:48 Maybe someone else does have a better idea for this?
The PR for MQTT Import that is still open (and could probably use a little TLC) would be able to do that, as there can be events for every configured JSON value, without directly connecting it to a (PCF)GPIO pin ;)
/Ton (PayPal.me)

Post Reply

Who is online

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