Skip to content

Commit 00389f9

Browse files
authored
Optional power message repetition configuration (#39)
* Revert "Increase message repetition count for power on/off messages (#34)" This reverts commit 77ecf73. * Add optional power message repetition configuration
1 parent 77ecf73 commit 00389f9

File tree

5 files changed

+50
-6
lines changed

5 files changed

+50
-6
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ A example configuration can be found [here](example.yaml)
2222
- **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.
2323
- **invert_power_pin**(**Optional**: boolean): If set to `true` the output of the power pin will be inverted. Defaults to `false`.
2424
- **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`.
25+
- **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`.
2526
- **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`.
2627

2728
## Philips Power switch
@@ -131,3 +132,12 @@ More information on the communication protocol used by this component can be fou
131132
- Make sure your wiring is correct
132133
- The UART debug function can be used to analyze communication and verify correct wiring
133134
- The commands used by the display unit may be different between different revisions/models (see Related Work)
135+
136+
## Display not turning on
137+
138+
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:
139+
140+
- Double-check wiring
141+
- Try increasing `power_message_repetitions` to `25` or some other value smaller/larger than this.
142+
- Try increasing `power_trip_delay`
143+
- Try adjusting `invert_power_pin` depending on the type of transistor used

components/philips_series_2200/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
CONTROLLER_ID = "controller_id"
1313
INVERT_POWER_PIN = "invert_power_pin"
1414
POWER_TRIP_DELAY = "power_trip_delay"
15+
CONF_POWER_MESSAGE_REPETITIONS = "power_message_repetitions"
1516

1617
CONF_COMMAND_SET = "model"
1718
COMMAND_SETS = {"EP_2220": "PHILIPS_EP2220"}
@@ -33,6 +34,7 @@
3334
max_included=cv.TimePeriod(milliseconds=10000),
3435
),
3536
),
37+
cv.Optional(CONF_POWER_MESSAGE_REPETITIONS, default=5): cv.positive_int,
3638
cv.Optional(CONF_COMMAND_SET, default="EP_2220"): cv.enum(
3739
COMMAND_SETS, upper=True, space="_"
3840
),
@@ -54,5 +56,6 @@ def to_code(config):
5456
cg.add(var.register_display_uart(display))
5557
cg.add(var.register_mainboard_uart(mainboard))
5658
cg.add(var.set_power_pin(pin))
59+
cg.add(var.set_power_message_repetitions(config[CONF_POWER_MESSAGE_REPETITIONS]))
5760
cg.add(var.set_invert_power_pin(config[INVERT_POWER_PIN]))
5861
cg.add(var.set_power_trip_delay(config[POWER_TRIP_DELAY]))

components/philips_series_2200/philips_series_2200.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,26 @@ namespace esphome
6868
initial_pin_state_ = !invert;
6969
}
7070

71+
/**
72+
* @brief Timer period for which the power pin is inverted
73+
*
74+
* @param time power trip length in ms
75+
*/
7176
void set_power_trip_delay(uint32_t time)
7277
{
7378
power_trip_delay_ = time;
7479
}
7580

81+
/**
82+
* @brief The number of message repetitions used while turning on the machine
83+
*
84+
* @param count numer of message to use
85+
*/
86+
void set_power_message_repetitions(uint count)
87+
{
88+
power_message_repetitions_ = count;
89+
}
90+
7691
#ifdef USE_SWITCH
7792
/**
7893
* @brief Reference to a power switch object.
@@ -85,6 +100,7 @@ namespace esphome
85100
power_switch->set_mainboard_uart(&mainboard_uart_);
86101
power_switch->set_power_pin(power_pin_);
87102
power_switch->set_power_trip_delay(power_trip_delay_);
103+
power_switch->set_power_message_repetitions(power_message_repetitions_);
88104
power_switch->set_initial_state(&initial_pin_state_);
89105
power_switches_.push_back(power_switch);
90106
};
@@ -144,6 +160,9 @@ namespace esphome
144160
/// @brief the initial power pin state (may be inverted through user configuration)
145161
bool initial_pin_state_ = true;
146162

163+
/// @brief the number of message repetitions to use while turning on the machine
164+
uint power_message_repetitions_ = 5;
165+
147166
/// @brief length of power outage applied to the display
148167
uint32_t power_trip_delay_ = 500;
149168

components/philips_series_2200/switch/power.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,20 @@ namespace esphome
4040
if (state)
4141
{
4242
// Send pre-power on message
43-
for (unsigned int i = 0; i <= POWER_MESSAGE_REPETITIONS; i++)
43+
for (unsigned int i = 0; i <= power_message_repetitions_; i++)
4444
mainboard_uart_->write_array(command_pre_power_on);
4545

4646
// Send power on message
4747
if (cleaning_)
4848
{
4949
// Send power on command with cleaning
50-
for (unsigned int i = 0; i <= POWER_MESSAGE_REPETITIONS; i++)
50+
for (unsigned int i = 0; i <= power_message_repetitions_; i++)
5151
mainboard_uart_->write_array(command_power_with_cleaning);
5252
}
5353
else
5454
{
5555
// Send power on command without cleaning
56-
for (unsigned int i = 0; i <= POWER_MESSAGE_REPETITIONS; i++)
56+
for (unsigned int i = 0; i <= power_message_repetitions_; i++)
5757
mainboard_uart_->write_array(command_power_without_cleaning);
5858
}
5959

@@ -66,7 +66,7 @@ namespace esphome
6666
else
6767
{
6868
// Send power off message
69-
for (unsigned int i = 0; i <= POWER_MESSAGE_REPETITIONS; i++)
69+
for (unsigned int i = 0; i <= power_message_repetitions_; i++)
7070
mainboard_uart_->write_array(command_power_off);
7171
mainboard_uart_->flush();
7272
}

components/philips_series_2200/switch/power.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "esphome/components/uart/uart.h"
66
#include "../commands.h"
77

8-
#define POWER_MESSAGE_REPETITIONS 25
8+
#define MESSAGE_REPETITIONS 5
99
#define POWER_TRIP_RETRY_DELAY 100
1010
#define MAX_POWER_TRIP_COUNT 5
1111

@@ -82,6 +82,16 @@ namespace esphome
8282
initial_state_ = initial_state;
8383
}
8484

85+
/**
86+
* @brief Sets the number of message repetitions to use while turning on the machine
87+
*
88+
* @param count number of repetitions
89+
*/
90+
void set_power_message_repetitions(uint count)
91+
{
92+
power_message_repetitions_ = count;
93+
}
94+
8595
/**
8696
* @brief Processes and publish the new switch state.
8797
*/
@@ -101,7 +111,9 @@ namespace esphome
101111
/// @brief Time of last power trip
102112
uint32_t last_power_trip_ = 0;
103113
/// @brief nr of power performed power trips
104-
int power_trip_count_ = 0;
114+
uint power_trip_count_ = 0;
115+
/// @brief determines how often the power on message is repeated
116+
uint power_message_repetitions_ = 5;
105117
/// @brief initial power state reference
106118
bool *initial_state_;
107119
};

0 commit comments

Comments
 (0)