I currently use esphome for various sensors like temperature and energy meters where esphome publish data to home assistant via its API. But how can I do it the other way around?
I would like a float entity in home assistant that, when it is updated, the state (temperature) is sent to esphome and is used to set a specific resistance for a MCP4161 (digital potentiometer) connected via SPI to a esp8266 (wemos d1 mini).
Can this even be done in esphome or should I write an arduino sketch that get the entity state via MQTT?
How can I rewrite this for esphome and replace the value “150” with the value from home assistant?
I know that I have to recalculate the temperature to a proper wiper value between 1-255 but first I need to find out how to get the custom spi component to work.
src/my_custom_spi_device.h: In member function 'virtual void MyCustomComponent::setup()':
src/my_custom_spi_device.h:11:5: error: 'SPI' was not declared in this scope
SPI.pins(SCK_PIN, MISO_PIN, MOSI_PIN, CS_PIN);
^
#include "esphome.h"
using namespace esphome;
class ad8400 : public FloatOutput, public Component {
public:
void setup() override {
// This will be called by App.setup()
pinMode(D8, OUTPUT);
SPI.begin();
}
void write_state(float state) override {
// state is the amount this output should be on, from 0.0 to 1.0
// we need to convert it to an integer first
int value = state * 255;
ESP_LOGD("custom", "Valore: %d", value);
ad8400write(value);
}
protected:
void ad8400write(int value) {
digitalWrite(D8, LOW);
SPI.transfer(0);
SPI.transfer(value);
digitalWrite(D8, HIGH);
}
};
My component was a ad8400 but it doesnt matter as is a spi component. You have to pass value with .setvalue() in range from 0.0 to 1.0 then inside the componet it is converted back to 1 to 255
I tried to add it with an include in the yaml file:
esphome:
includes:
- my_custom_spi_device.h
But I get the following errors when trying to compile:
In file included from src/main.cpp:12:0:
src/my_custom_spi_device.h:4:34: error: expected class-name before ‘,’ token
class ad8400 : public FloatOutput, public Component {
^
src/my_custom_spi_device.h:12:8: error: ‘void ad8400::write_state(float)’ marked override, but does not override
void write_state(float state) override {
^
src/my_custom_spi_device.h: In member function ‘virtual void ad8400::setup()’:
src/my_custom_spi_device.h:9:5: error: ‘SPI’ was not declared in this scope
SPI.begin();
^
src/my_custom_spi_device.h: In member function ‘void ad8400::ad8400write(int)’:
src/my_custom_spi_device.h:22:5: error: ‘SPI’ was not declared in this scope
SPI.transfer(0);
^
*** [/data/testnode/.pioenvs/testnode/src/main.cpp.o] Error 1
It is now compiling without error I just need to figure out how to get the entity in HA. The state of this entity should be used as value in MyCustomFloatOutput
I also would like to set a 150kΩ digital potentiometer with esp8266 to work in Home Assistant. This subject should be very popular. It is very useful for a lot of things.
I’m very interested in learning how to do this. I have several of the Xaiomi temperature sensors, and would like to figure out a way to use their average and input that into my T6 Honeywell thermostat.
Here’s the connection. I have multiple Xiaomi thermometers around the house. Each of them connect via BLE to an ESP32 that sends their updates via Wi-Fi to home assistant. I can easily average those temperature reading, or get the min/max. I also have a T6 Honeywell thermostat that is integrated with HA. Now the T6 has an input for a remote temperature sensor (thermistor), but it has to be wired in. Since I already have all of these Xiaomi sensors around the house, I thought it would be nice to use their average as an input to the Thermostat rather than just having it use one point of measurement at the thermostat. My idea was to use another ESP32 with a digipot to set the resistance that correlates to the average of the Xiaomi temperatures. The digipot would then be wired into the thermostat emulating a thermistor. Make sense?