How to read a variable from a custom_component (wiegand)

I have not an esp32. Just ordered one yesterday but i have to wait some week until it arrive to me… (Aliexpress).
My wemos d1 mini is working well with other firmwares (Tasmota or even ESPhome).

Yes, but which pins did you use in the .yaml looks like conf pins problem

I used gpio 4 and 5 for d0 and d1. I don’t know if this can be wrong…

In the Esphome documentation says that pin 4 is output Only.

Tried other ports but the result is the same. I think esp8266 has a different interrupt managment respect to esp32.

Hi,
finally i have my esp32 card. I tried again to load your code but unfortunately it doesn’t compile. I have this errors. I used .h and .yaml from your github.

INFO Reading configuration /config/esphome/door_reader.yaml...
INFO Detected timezone 'CET' with UTC offset 1 and daylight savings time from 28 March 02:00:00 to 31 October 03:00:00
INFO Generating C++ source...
INFO Compiling app...
INFO Running:  platformio run -d /config/esphome/door_reader
Processing door_reader (board: esp32doit-devkit-v1; framework: arduino; platform: [email protected])
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
Dependency Graph
|-- <AsyncTCP-esphome> 1.1.1
|-- <ESPmDNS> 1.0
|   |-- <WiFi> 1.0
|-- <FS> 1.0
|-- <ESPAsyncWebServer-esphome> 1.2.6
|   |-- <AsyncTCP-esphome> 1.1.1
|   |-- <FS> 1.0
|   |-- <WiFi> 1.0
|   |-- <ArduinoJson-esphomelib> 5.13.3
|-- <AsyncMqttClient-esphome> 0.8.4
|   |-- <AsyncTCP-esphome> 1.1.1
|-- <ArduinoJson-esphomelib> 5.13.3
|-- <DNSServer> 1.1.0
|   |-- <WiFi> 1.0
|-- <Update> 1.0
|-- <WiFi> 1.0
Compiling /data/door_reader/.pioenvs/door_reader/src/main.cpp.o
Archiving /data/door_reader/.pioenvs/door_reader/libcb6/libESPAsyncWebServer-esphome_ID6758.a
Compiling /data/door_reader/.pioenvs/door_reader/lib4eb/AsyncMqttClient-esphome_ID6759/AsyncMqttClient/Packets/PingRespPacket.cpp.o
Compiling /data/door_reader/.pioenvs/door_reader/lib4eb/AsyncMqttClient-esphome_ID6759/AsyncMqttClient/Packets/PubAckPacket.cpp.o
Compiling /data/door_reader/.pioenvs/door_reader/lib4eb/AsyncMqttClient-esphome_ID6759/AsyncMqttClient/Packets/PubCompPacket.cpp.o
In file included from src/main.cpp:17:0:
src/wiegand_device.h: In member function 'void WiegandReader::json_message(std::__cxx11::string)':
src/wiegand_device.h:98:14: error: no matching function for call to 'WiegandReader::publish_json(String&, WiegandReader::json_message(std::__cxx11::string)::<lambda(ArduinoJson::JsonObject&)>)'
             });
              ^
In file included from src/esphome.h:17:0,
                 from src/main.cpp:3:
src/esphome/components/mqtt/custom_mqtt_device.h:166:8: note: candidate: bool esphome::mqtt::CustomMQTTDevice::publish_json(const string&, const json_build_t&, uint8_t, bool)
   bool publish_json(const std::string &topic, const json::json_build_t &f, uint8_t qos, bool retain);
        ^
src/esphome/components/mqtt/custom_mqtt_device.h:166:8: note:   candidate expects 4 arguments, 2 provided
src/esphome/components/mqtt/custom_mqtt_device.h:183:8: note: candidate: bool esphome::mqtt::CustomMQTTDevice::publish_json(const string&, const json_build_t&)
   bool publish_json(const std::string &topic, const json::json_build_t &f);
        ^
src/esphome/components/mqtt/custom_mqtt_device.h:183:8: note:   no known conversion for argument 1 from 'String' to 'const string& {aka const std::__cxx11::basic_string<char>&}'
In file included from src/main.cpp:17:0:
src/wiegand_device.h: In member function 'void WiegandReader::json_message2(long unsigned int)':
src/wiegand_device.h:110:14: error: no matching function for call to 'WiegandReader::publish_json(String&, WiegandReader::json_message2(long unsigned int)::<lambda(ArduinoJson::JsonObject&)>)'
             });
              ^
In file included from src/esphome.h:17:0,
                 from src/main.cpp:3:
src/esphome/components/mqtt/custom_mqtt_device.h:166:8: note: candidate: bool esphome::mqtt::CustomMQTTDevice::publish_json(const string&, const json_build_t&, uint8_t, bool)
   bool publish_json(const std::string &topic, const json::json_build_t &f, uint8_t qos, bool retain);
        ^
src/esphome/components/mqtt/custom_mqtt_device.h:166:8: note:   candidate expects 4 arguments, 2 provided
src/esphome/components/mqtt/custom_mqtt_device.h:183:8: note: candidate: bool esphome::mqtt::CustomMQTTDevice::publish_json(const string&, const json_build_t&)
   bool publish_json(const std::string &topic, const json::json_build_t &f);
        ^
src/esphome/components/mqtt/custom_mqtt_device.h:183:8: note:   no known conversion for argument 1 from 'String' to 'const string& {aka const std::__cxx11::basic_string<char>&}'
*** [/data/door_reader/.pioenvs/door_reader/src/main.cpp.o] Error 1
========================= [FAILED] Took 17.95 seconds =========================

Try to use the same code that already compiled for you mini D1 but changing the board to ESP32.
I am not where I have Hassio installed so I can´t check how I built it, sorry. Looking the error code looks like you dont have the weigand_device.h in the propper place.

The code is the same… I’m sure wiegand_device is in the right place, otherwise compile process doesn’t start at all… It seems that no one is interesting in wiegand readers in domotics :frowning:
They are not supported in Tasmota, Esphome etc. I would try to build from myself a custom sensor but i have not enough skills to do so.

Hello,
Thanks for the custom_component (wiegand) example. I was able to run it, on esp32-cam and the main functionality works (device transmits data to home assistant), but if I also add camera component, camera does not work. If I remove custom_component(wiegand) camera works.

Does anybody know what can be the reason for this?

I checked GPIO and I am not using camera pins in custom component.

esp32_camera:
  external_clock:
    pin: GPIO0
    frequency: 20MHz
  i2c_pins:
    sda: GPIO26
    scl: GPIO27
  data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35]
  vsync_pin: GPIO25
  href_pin: GPIO23
  pixel_clock_pin: GPIO22
  power_down_pin: GPIO32
  resolution: VGA
  brightness: 2
  jpeg_quality: 10
  idle_framerate: 0.05 fps

  name: room1_build1
    

switch:
- platform: gpio
  pin: 13
  name: "First sw"
  id: gpio_sw
- platform: gpio
  pin: 33
  name: "Second sw"
  id: gpio_sw2



custom_component:
  - lambda: |-
       auto wiegand = new WiegandReader(12, 4, "script.to_call");
       return {wiegand};