Comments (1)
After a long time, i decided to work again with this chip. I used the library above and added missing function for reading input register (https://github.com/NicoFR75/PCA9533).
With using the custom binarysensor, custom floatoutput and custom switch, i manage to make it work.
Below the code is used if someone want to use this chip
I have 3 files (one per custom type) included in my YAML config file, the setup part is the same for the 3 files.
YAML
For binarysensor (detect switch position):
binary_sensor:
- platform: custom
lambda: |-
auto pca9533_binarysensor = new PCA9533_BinarySensor_IO2();
App.register_component(pca9533_binarysensor);
return {pca9533_binarysensor};
binary_sensors:
name: '233_Interrupteur_IO2'
on_state:
then:
- light.toggle:
id: light_pwm
transition_length: 500ms
- platform: custom
lambda: |-
auto pca9533_binarysensor = new PCA9533_BinarySensor_IO3();
App.register_component(pca9533_binarysensor);
return {pca9533_binarysensor};
binary_sensors:
name: '233_Interrupteur_IO3'
on_state:
then:
- switch.toggle:
id: custom_switch
For switch (i use it to command a relay for light bulb):
switch:
- platform: custom
lambda: |-
auto pca9533_switch = new PCA9533_Switch_IO1();
App.register_component(pca9533_switch);
return {pca9533_switch};
switches:
name: "233_Relai"
id: custom_switch
inverted: true
For output (linked to a light for dimming led):
output:
- platform: custom
type: float
lambda: |-
auto pca9533_floatoutput = new PCA9533_FloatOutput_IO0();
App.register_component(pca9533_floatoutput);
return {pca9533_floatoutput};
outputs:
id: custom_floatoutput
light:
- platform: monochromatic
name: "233_Variateur"
id: light_pwm
output: custom_floatoutput
.H FILES
For binarysensor :
#include "esphome.h"
#include "PCA9533.h"
using namespace esphome::binary_sensor;
class PCA9533_BinarySensor_IO2 : public Component, public BinarySensor {
public:
PCA9533 myself;
void setup() override {
// Setup PCA9533
myself.init();
myself.setPSC(REG_PSC0, 0); // Prescaler for PWM0 150Hz
myself.setPSC(REG_PSC1, 0); // Prescaler for PWM1 150Hz
myself.setMODE(IO0, LED_MODE_PWM0);
myself.setMODE(IO1, LED_MODE_OFF);
myself.setMODE(IO2, LED_MODE_OFF);
myself.setMODE(IO3, LED_MODE_OFF);
}
void loop() override {
bool state = myself.getINPUT(IO2);
publish_state(state);
}
};
class PCA9533_BinarySensor_IO3 : public Component, public BinarySensor {
public:
PCA9533 myself;
void setup() override {
// Setup PCA9533
myself.init();
myself.setPSC(REG_PSC0, 0); // Prescaler for PWM0 150Hz
myself.setPSC(REG_PSC1, 0); // Prescaler for PWM1 150Hz
myself.setMODE(IO0, LED_MODE_PWM0);
myself.setMODE(IO1, LED_MODE_OFF);
myself.setMODE(IO2, LED_MODE_OFF);
myself.setMODE(IO3, LED_MODE_OFF);
}
void loop() override {
bool state = myself.getINPUT(IO3);
publish_state(state);
}
};
For switch :
#include "esphome.h"
#include "PCA9533.h"
using namespace esphome::output;
class PCA9533_Switch_IO1 : public Component, public Switch {
public:
PCA9533 myself;
void setup() override {
// Setup PCA9533
myself.init();
myself.setPSC(REG_PSC0, 0); // Prescaler for PWM0 150Hz
myself.setPSC(REG_PSC1, 0); // Prescaler for PWM1 150Hz
myself.setMODE(IO0, LED_MODE_PWM0);
myself.setMODE(IO1, LED_MODE_OFF);
myself.setMODE(IO2, LED_MODE_OFF);
myself.setMODE(IO3, LED_MODE_OFF);
}
void write_state(bool state) override {
if (state) {
myself.setMODE(IO1, LED_MODE_OFF);
}
else {
myself.setMODE(IO1, LED_MODE_ON);
}
publish_state(state);
}
};
For floatoutput :
#include "esphome.h"
#include "PCA9533.h"
using namespace esphome::output;
class PCA9533_FloatOutput_IO0 : public Component, public FloatOutput {
public:
PCA9533 myself;
void setup() override {
// Setup PCA9533
myself.init();
myself.setPSC(REG_PSC0, 0); // Prescaler for PWM0 150Hz
myself.setPSC(REG_PSC1, 0); // Prescaler for PWM1 150Hz
myself.setMODE(IO0, LED_MODE_PWM0);
myself.setMODE(IO1, LED_MODE_OFF);
myself.setMODE(IO2, LED_MODE_OFF);
myself.setMODE(IO3, LED_MODE_OFF);
}
void write_state(float state) override {
int value = state * 255;
myself.setPWM(REG_PWM0, value);
}
};
from feature-requests.
Related Issues (20)
- Add decoder/IR remote receiver support for Bang & Olufsen protocol
- Ability to choose an arbitrary STT service HOT 3
- Separate Camera functionality from esp32_camera to make it reusable by other components HOT 1
- Allow custom pin schema for Dallas component
- Support for m5dial touch driver HOT 2
- Alternative method for h-bridge light
- ld2410 dynamic throttle HOT 1
- ModBus ASCII
- Adding the last 3 bytes of the MAC address to the device name in the MQTT topic_prefix.
- Allow configuration of the dashboard base path HOT 7
- Feature request: 55% bigger partitions with two phase OTA HOT 3
- support commit SHA as legal value in ref in external_components/source
- PIPSOLAR - switches needed for charger_source_priority
- Update bottun in the Kamstrup mc40x component
- IRK Sensor/Onboarding for Private BLE HOT 1
- Please add support of Mitsubishi Electric MSZ-HJxxVA to ir_climate devices library HOT 1
- DFROBOT Capacitive Soil Moisture Sensor
- ESPHome Home Assistent add-on Update All and GUI
- S0 output generator HOT 5
- Add an new component ad5291 5292 Digital Potentiometers HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from feature-requests.