ESPHome
2026.11.0b6
Loading...
Searching...
No Matches
esphome
components
pzem004t
pzem004t.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
esphome/core/component.h
"
4
#include "
esphome/components/uart/uart.h
"
5
#include "
esphome/components/sensor/sensor.h
"
6
7
namespace
esphome::pzem004t
{
8
9
class
PZEM004T
final :
public
PollingComponent
,
public
uart::UARTDevice
{
10
SUB_SENSOR(voltage)
11
SUB_SENSOR(current)
12
SUB_SENSOR(power)
13
SUB_SENSOR(energy)
14
15
public
:
16
void
setup
()
override
;
17
18
void
loop()
override
;
19
20
void
update()
override
;
21
22
void
dump_config()
override
;
23
24
protected
:
25
enum
PZEM004TReadState
{
26
SET_ADDRESS
= 0xB4,
27
READ_VOLTAGE
= 0xB0,
28
READ_CURRENT
= 0xB1,
29
READ_POWER
= 0xB2,
30
READ_ENERGY
= 0xB3,
31
DONE
= 0x00,
32
} read_state_{
DONE
};
33
34
void
write_state_
(
PZEM004TReadState
state
);
35
36
uint32_t
last_read_
{0};
37
};
38
39
}
// namespace esphome::pzem004t
esphome::Component::setup
virtual void setup()
Where the component's initialization should happen.
Definition
component.cpp:84
esphome::PollingComponent
This class simplifies creating components that periodically check a state.
Definition
component.h:532
esphome::pzem004t::PZEM004T
Definition
pzem004t.h:9
esphome::pzem004t::PZEM004T::last_read_
uint32_t last_read_
Definition
pzem004t.h:36
esphome::pzem004t::PZEM004T::DONE
enum esphome::pzem004t::PZEM004T::PZEM004TReadState DONE
esphome::pzem004t::PZEM004T::PZEM004TReadState
PZEM004TReadState
Definition
pzem004t.h:25
esphome::pzem004t::PZEM004T::SET_ADDRESS
@ SET_ADDRESS
Definition
pzem004t.h:26
esphome::pzem004t::PZEM004T::READ_CURRENT
@ READ_CURRENT
Definition
pzem004t.h:28
esphome::pzem004t::PZEM004T::READ_VOLTAGE
@ READ_VOLTAGE
Definition
pzem004t.h:27
esphome::pzem004t::PZEM004T::READ_ENERGY
@ READ_ENERGY
Definition
pzem004t.h:30
esphome::pzem004t::PZEM004T::READ_POWER
@ READ_POWER
Definition
pzem004t.h:29
esphome::pzem004t::PZEM004T::write_state_
void write_state_(PZEM004TReadState state)
Definition
pzem004t.cpp:94
esphome::uart::UARTDevice
Definition
uart.h:15
component.h
state
bool state
Definition
fan.h:2
esphome::pzem004t
Definition
pzem004t.cpp:7
uint32_t
static void uint32_t
Definition
crash_handler.cpp:153
sensor.h
uart.h
Generated by
1.12.0