Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions esphome/components/navien/navien.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,6 @@ namespace navien {
static const char *TAG = "navien.sensor";

void Navien::setup() {
ESP_LOGCONFIG(TAG, "Setting rs485 into receive mode");
// Set the rs485 into receive mode
//pinMode(D5, OUTPUT);
//digitalWrite(D5, LOW);

// Set the driver into regular mode (from undefined startup)
ESP_LOGCONFIG(TAG, "Activating TTL/CMOS buffer");
pinMode(D6, OUTPUT);
digitalWrite(D6, HIGH);


pinMode(D2, OUTPUT);
digitalWrite(D2, HIGH);

this->state.power = POWER_OFF;

this->received_cnt = 0;
Expand Down Expand Up @@ -67,6 +53,7 @@ void Navien::update() {
if (this->water_flow_sensor != nullptr)
this->water_flow_sensor->publish_state(this->state.water.flow_lpm);

#ifdef USE_SWITCH
if (this->power_switch != nullptr){
switch(this->state.power){
case POWER_ON:
Expand All @@ -76,6 +63,7 @@ void Navien::update() {
this->power_switch->publish_state(false);
}
}
#endif
}

bool Navien::seek_to_marker(){
Expand Down Expand Up @@ -117,7 +105,7 @@ void Navien::parse_water(){

this->state.water.flow_lpm = Navien::flow2lpm(this->recv_buffer.water.water_flow);

uint8 power = this->recv_buffer.water.system_power;
uint8_t power = this->recv_buffer.water.system_power;
if (power & POWER_STATUS_ON_OFF_MASK)
this->state.power = POWER_ON;
else
Expand Down Expand Up @@ -213,7 +201,7 @@ void Navien::parse_packet(){
break;
}

// ESP_LOGV(TAG, "Calculated checksum over %d bytes => 0x%02X", HDR_SIZE + this->recv_buffer.hdr.len, crc);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with this change, but it should not have been broken the compilation since the line is commented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I found that with an older revision where it was still uncommented. So I just transferred my fix to this line even though it's now commented out.

// ESP_LOGV(TAG, "Calculated checksum over %d bytes => 0x%02X", HDR_SIZE + this->recv_buffer.hdr.len, crc_c);

}

Expand Down Expand Up @@ -284,7 +272,7 @@ void Navien::loop() {
}
}

void Navien::send_cmd(const uint8_t * buffer, uint8 len){
void Navien::send_cmd(const uint8_t * buffer, uint8_t len){
/* if (buffer && len){
this->write_array(buffer, len);
}*/
Expand Down Expand Up @@ -397,6 +385,7 @@ uint8_t Navien::checksum(const uint8_t * buffer, uint8_t len, uint16_t seed){
return result;
}

#ifdef USE_SWITCH
void NavienOnOffSwitch::setup() {
ESP_LOGCONFIG(TAG, "Setting up Switch '%s'...", this->name_.c_str());

Expand Down Expand Up @@ -430,8 +419,10 @@ void NavienOnOffSwitch::set_parent(Navien * parent) {
void NavienOnOffSwitch::dump_config(){
ESP_LOGCONFIG(TAG, "Empty custom switch");
}
#endif


#ifdef USE_BUTTON
void NavienHotButton::setup() {
ESP_LOGCONFIG(TAG, "Setting up Button '%s'...", this->name_.c_str());
}
Expand All @@ -448,6 +439,7 @@ void NavienHotButton::set_parent(Navien * parent) {
void NavienHotButton::dump_config(){
ESP_LOGCONFIG(TAG, "Navien Hot Button");
}
#endif

} // namespace navien
} // namespace esphome
12 changes: 11 additions & 1 deletion esphome/components/navien/navien.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

#include "esphome/core/component.h"
#include "esphome/components/sensor/sensor.h"
#ifdef USE_SWITCH
#include "esphome/components/switch/switch.h"
#endif
#include "esphome/components/uart/uart.h"

namespace esphome {
Expand Down Expand Up @@ -277,7 +279,7 @@ class Navien : public PollingComponent, public uart::UARTDevice {
void send_hot_button_cmd();

protected:
void send_cmd(const uint8_t * buffer, uint8 len);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

void send_cmd(const uint8_t * buffer, uint8_t len);

protected:
// Keeps track of the state machine and iterates through
Expand Down Expand Up @@ -310,7 +312,9 @@ class Navien : public PollingComponent, public uart::UARTDevice {
void set_outlet_temp_sensor(sensor::Sensor *sensor) { outlet_temp_sensor = sensor; }
void set_water_flow_sensor(sensor::Sensor *sensor) { water_flow_sensor = sensor; }

#ifdef USE_SWITCH
void set_power_switch(switch_::Switch * ps){power_switch = ps;}
#endif
protected:
/**
* Sensor definitions
Expand All @@ -320,9 +324,12 @@ class Navien : public PollingComponent, public uart::UARTDevice {
sensor::Sensor *inlet_temp_sensor;
sensor::Sensor *water_flow_sensor;

#ifdef USE_SWITCH
switch_::Switch *power_switch;
#endif
};

#ifdef USE_SWITCH
class NavienOnOffSwitch : public switch_::Switch, public Component {
protected:
Navien * parent;
Expand All @@ -333,7 +340,9 @@ class NavienOnOffSwitch : public switch_::Switch, public Component {
void write_state(bool state) override;
void dump_config() override;
};
#endif

#ifdef USE_BUTTON
class NavienHotButton : public button::Button, public Component {
protected:
Navien * parent;
Expand All @@ -345,6 +354,7 @@ class NavienHotButton : public button::Button, public Component {
void press_action() override;
void dump_config() override;
};
#endif

} // namespace navien
} // namespace esphome
11 changes: 11 additions & 0 deletions esphome/navien.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ api:
ota:


output:
# Set the rs485 into receive mode
- platform: gpio
pin: GPIO14
inverted: true
id: uart_rs485_receive_mode
# Set the driver into regular mode (from undefined startup)
- platform: gpio
pin: GPIO12
id: uart_driver_regular_mode

uart:
tx_pin: GPIO15
rx_pin:
Expand Down