Skip to content

Commit

Permalink
Optional power message repetition configuration (#39)
Browse files Browse the repository at this point in the history
* Revert "Increase message repetition count for power on/off messages (#34)"

This reverts commit 77ecf73.

* Add optional power message repetition configuration
  • Loading branch information
TillFleisch authored Feb 14, 2024
1 parent 77ecf73 commit 00389f9
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ A example configuration can be found [here](example.yaml)
- **power_pin**(**Required**, [Pin](https://esphome.io/guides/configuration-types.html#config-pin)): Pin to which the MOSFET/Transistor is connected. This pin is used to temporarily turn of the display unit.
- **invert_power_pin**(**Optional**: boolean): If set to `true` the output of the power pin will be inverted. Defaults to `false`.
- **power_trip_delay**(**Optional**: Time): Determines the length of the power outage applied to the display unit, which is to trick it into turning on. Defaults to `500ms`.
- **power_message_repetitions**(**Optional**: uint): Determines how many message repetitions are used while turning on the machine. On some hardware combinations a higher value such as `25` is required to turn on the display successfully. Defaults to `5`.
- **model**(**Optional**: int): Different models or revisions may use different commands. This option can be used to specify the command set used by this component. Select one of `EP2220`. Defaults to `EP2220`.

## Philips Power switch
Expand Down Expand Up @@ -131,3 +132,12 @@ More information on the communication protocol used by this component can be fou
- Make sure your wiring is correct
- The UART debug function can be used to analyze communication and verify correct wiring
- The commands used by the display unit may be different between different revisions/models (see Related Work)
## Display not turning on
With some Hardware combinations and on some coffee machines, the display might not turn on reliably. If this is the case for you please try the following troubleshooting steps to resolve the issue:
- Double-check wiring
- Try increasing `power_message_repetitions` to `25` or some other value smaller/larger than this.
- Try increasing `power_trip_delay`
- Try adjusting `invert_power_pin` depending on the type of transistor used
3 changes: 3 additions & 0 deletions components/philips_series_2200/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
CONTROLLER_ID = "controller_id"
INVERT_POWER_PIN = "invert_power_pin"
POWER_TRIP_DELAY = "power_trip_delay"
CONF_POWER_MESSAGE_REPETITIONS = "power_message_repetitions"

CONF_COMMAND_SET = "model"
COMMAND_SETS = {"EP_2220": "PHILIPS_EP2220"}
Expand All @@ -33,6 +34,7 @@
max_included=cv.TimePeriod(milliseconds=10000),
),
),
cv.Optional(CONF_POWER_MESSAGE_REPETITIONS, default=5): cv.positive_int,
cv.Optional(CONF_COMMAND_SET, default="EP_2220"): cv.enum(
COMMAND_SETS, upper=True, space="_"
),
Expand All @@ -54,5 +56,6 @@ def to_code(config):
cg.add(var.register_display_uart(display))
cg.add(var.register_mainboard_uart(mainboard))
cg.add(var.set_power_pin(pin))
cg.add(var.set_power_message_repetitions(config[CONF_POWER_MESSAGE_REPETITIONS]))
cg.add(var.set_invert_power_pin(config[INVERT_POWER_PIN]))
cg.add(var.set_power_trip_delay(config[POWER_TRIP_DELAY]))
19 changes: 19 additions & 0 deletions components/philips_series_2200/philips_series_2200.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,26 @@ namespace esphome
initial_pin_state_ = !invert;
}

/**
* @brief Timer period for which the power pin is inverted
*
* @param time power trip length in ms
*/
void set_power_trip_delay(uint32_t time)
{
power_trip_delay_ = time;
}

/**
* @brief The number of message repetitions used while turning on the machine
*
* @param count numer of message to use
*/
void set_power_message_repetitions(uint count)
{
power_message_repetitions_ = count;
}

#ifdef USE_SWITCH
/**
* @brief Reference to a power switch object.
Expand All @@ -85,6 +100,7 @@ namespace esphome
power_switch->set_mainboard_uart(&mainboard_uart_);
power_switch->set_power_pin(power_pin_);
power_switch->set_power_trip_delay(power_trip_delay_);
power_switch->set_power_message_repetitions(power_message_repetitions_);
power_switch->set_initial_state(&initial_pin_state_);
power_switches_.push_back(power_switch);
};
Expand Down Expand Up @@ -144,6 +160,9 @@ namespace esphome
/// @brief the initial power pin state (may be inverted through user configuration)
bool initial_pin_state_ = true;

/// @brief the number of message repetitions to use while turning on the machine
uint power_message_repetitions_ = 5;

/// @brief length of power outage applied to the display
uint32_t power_trip_delay_ = 500;

Expand Down
8 changes: 4 additions & 4 deletions components/philips_series_2200/switch/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ namespace esphome
if (state)
{
// Send pre-power on message
for (unsigned int i = 0; i <= POWER_MESSAGE_REPETITIONS; i++)
for (unsigned int i = 0; i <= power_message_repetitions_; i++)
mainboard_uart_->write_array(command_pre_power_on);

// Send power on message
if (cleaning_)
{
// Send power on command with cleaning
for (unsigned int i = 0; i <= POWER_MESSAGE_REPETITIONS; i++)
for (unsigned int i = 0; i <= power_message_repetitions_; i++)
mainboard_uart_->write_array(command_power_with_cleaning);
}
else
{
// Send power on command without cleaning
for (unsigned int i = 0; i <= POWER_MESSAGE_REPETITIONS; i++)
for (unsigned int i = 0; i <= power_message_repetitions_; i++)
mainboard_uart_->write_array(command_power_without_cleaning);
}

Expand All @@ -66,7 +66,7 @@ namespace esphome
else
{
// Send power off message
for (unsigned int i = 0; i <= POWER_MESSAGE_REPETITIONS; i++)
for (unsigned int i = 0; i <= power_message_repetitions_; i++)
mainboard_uart_->write_array(command_power_off);
mainboard_uart_->flush();
}
Expand Down
16 changes: 14 additions & 2 deletions components/philips_series_2200/switch/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "esphome/components/uart/uart.h"
#include "../commands.h"

#define POWER_MESSAGE_REPETITIONS 25
#define MESSAGE_REPETITIONS 5
#define POWER_TRIP_RETRY_DELAY 100
#define MAX_POWER_TRIP_COUNT 5

Expand Down Expand Up @@ -82,6 +82,16 @@ namespace esphome
initial_state_ = initial_state;
}

/**
* @brief Sets the number of message repetitions to use while turning on the machine
*
* @param count number of repetitions
*/
void set_power_message_repetitions(uint count)
{
power_message_repetitions_ = count;
}

/**
* @brief Processes and publish the new switch state.
*/
Expand All @@ -101,7 +111,9 @@ namespace esphome
/// @brief Time of last power trip
uint32_t last_power_trip_ = 0;
/// @brief nr of power performed power trips
int power_trip_count_ = 0;
uint power_trip_count_ = 0;
/// @brief determines how often the power on message is repeated
uint power_message_repetitions_ = 5;
/// @brief initial power state reference
bool *initial_state_;
};
Expand Down

0 comments on commit 00389f9

Please sign in to comment.