remote_transmitter.transmit_cc1101

This commit is contained in:
Gábor Poczkodi 2024-02-29 22:34:59 +01:00
parent fa5d6955a7
commit 752cd75f46
10 changed files with 50 additions and 55 deletions

View file

@ -4,9 +4,12 @@ from esphome import automation, pins
from esphome.components import sensor from esphome.components import sensor
from esphome.components import spi from esphome.components import spi
from esphome.automation import maybe_simple_id from esphome.automation import maybe_simple_id
from esphome.components import remote_base
from esphome.const import ( from esphome.const import (
CONF_ID, CONF_ID,
CONF_FREQUENCY, CONF_FREQUENCY,
CONF_PROTOCOL,
CONF_CODE,
UNIT_EMPTY, UNIT_EMPTY,
UNIT_DECIBEL_MILLIWATT, UNIT_DECIBEL_MILLIWATT,
DEVICE_CLASS_SIGNAL_STRENGTH, DEVICE_CLASS_SIGNAL_STRENGTH,
@ -14,7 +17,7 @@ from esphome.const import (
) )
DEPENDENCIES = ["spi"] DEPENDENCIES = ["spi"]
AUTO_LOAD = ["sensor"] AUTO_LOAD = ["sensor", "remote_base"]
CODEOWNERS = ["@gabest11"] CODEOWNERS = ["@gabest11"]
@ -23,12 +26,11 @@ CONF_BANDWIDTH = "bandwidth"
# CONF_FREQUENCY = "frequency" # CONF_FREQUENCY = "frequency"
CONF_RSSI = "rssi" CONF_RSSI = "rssi"
CONF_LQI = "lqi" CONF_LQI = "lqi"
CONF_CC1101_ID = "cc1101_id"
cc1101_ns = cg.esphome_ns.namespace("cc1101") ns = cg.esphome_ns.namespace("cc1101")
CC1101 = cc1101_ns.class_("CC1101", cg.PollingComponent, spi.SPIDevice)
BeginTxAction = cc1101_ns.class_("BeginTxAction", automation.Action) CC1101 = ns.class_("CC1101", cg.PollingComponent, spi.SPIDevice)
EndTxAction = cc1101_ns.class_("EndTxAction", automation.Action)
CONFIG_SCHEMA = ( CONFIG_SCHEMA = (
cv.Schema( cv.Schema(
@ -54,21 +56,6 @@ CONFIG_SCHEMA = (
.extend(spi.spi_device_schema(cs_pin_required=True)) .extend(spi.spi_device_schema(cs_pin_required=True))
) )
CC1101_ACTION_SCHEMA = maybe_simple_id(
{
cv.Required(CONF_ID): cv.use_id(CC1101),
}
)
@automation.register_action("cc1101.begin_tx", BeginTxAction, CC1101_ACTION_SCHEMA)
@automation.register_action("cc1101.end_tx", EndTxAction, CC1101_ACTION_SCHEMA)
async def cc1101_action_to_code(config, action_id, template_arg, args):
var = cg.new_Pvariable(action_id, template_arg)
await cg.register_parented(var, config[CONF_ID])
return var
async def to_code(config): async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID]) var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config) await cg.register_component(var, config)
@ -85,3 +72,25 @@ async def to_code(config):
if CONF_LQI in config: if CONF_LQI in config:
lqi = await sensor.new_sensor(config[CONF_LQI]) lqi = await sensor.new_sensor(config[CONF_LQI])
cg.add(var.set_config_lqi_sensor(lqi)) cg.add(var.set_config_lqi_sensor(lqi))
CC1101RawAction = ns.class_("CC1101RawAction", remote_base.RemoteTransmitterActionBase)
CC1101_TRANSMIT_SCHEMA = (
cv.Schema(
{
cv.GenerateID(CONF_CC1101_ID): cv.use_id(CC1101),
}
)
.extend(remote_base.REMOTE_TRANSMITTABLE_SCHEMA)
.extend(remote_base.RC_SWITCH_RAW_SCHEMA)
.extend(remote_base.RC_SWITCH_TRANSMITTER)
)
@remote_base.register_action("cc1101", CC1101RawAction, CC1101_TRANSMIT_SCHEMA)
async def cc1101_action(var, config, args):
proto = await cg.templatable(
config[CONF_PROTOCOL], args, remote_base.RCSwitchBase, to_exp=remote_base.build_rc_switch_protocol
)
cg.add(var.set_protocol(proto))
cg.add(var.set_code(await cg.templatable(config[CONF_CODE], args, cg.std_string)))
await cg.register_parented(var, config[CONF_CC1101_ID])

View file

@ -12,8 +12,6 @@
On ESP32, this will not work, you must connect two separate pins. TX to GDO0, RX to GDO2. On ESP32, this will not work, you must connect two separate pins. TX to GDO0, RX to GDO2.
If only TX works, they are probably switched. If only TX works, they are probably switched.
Transferst must be surrounded with cc1101.begin_tx and cc1101.end_tx.
The source code is a mashup of the following github projects with some special esphome sauce: The source code is a mashup of the following github projects with some special esphome sauce:
https://github.com/dbuezas/esphome-cc1101 (the original esphome component) https://github.com/dbuezas/esphome-cc1101 (the original esphome component)

View file

@ -3,6 +3,7 @@
#include "esphome/core/component.h" #include "esphome/core/component.h"
#include "esphome/components/sensor/sensor.h" #include "esphome/components/sensor/sensor.h"
#include "esphome/components/spi/spi.h" #include "esphome/components/spi/spi.h"
#include "esphome/components/remote_base/rc_switch_protocol.h"
namespace esphome { namespace esphome {
namespace cc1101 { namespace cc1101 {
@ -89,14 +90,15 @@ class CC1101 : public PollingComponent,
void end_tx(); void end_tx();
}; };
template<typename... Ts> class BeginTxAction : public Action<Ts...>, public Parented<CC1101> { template<typename... Ts> class CC1101RawAction : public remote_base::RCSwitchRawAction<Ts...>, public Parented<CC1101> {
public: protected:
void play(Ts... x) override { this->parent_->begin_tx(); } void play(Ts... x) override {
}; this->parent_->begin_tx();
remote_base::RCSwitchRawAction<Ts...>::play(x...);
this->parent_->end_tx();
}
template<typename... Ts> class EndTxAction : public Action<Ts...>, public Parented<CC1101> {
public: public:
void play(Ts... x) override { this->parent_->end_tx(); }
}; };
} // namespace cc1101 } // namespace cc1101

View file

@ -51,8 +51,7 @@ button:
- platform: template - platform: template
name: "Gate" name: "Gate"
on_press: on_press:
- cc1101.begin_tx: transceiver - remote_transmitter.transmit_cc1101:
- remote_transmitter.transmit_rc_switch_raw:
transmitter_id: realtx transmitter_id: realtx
code: '0111000110010011110110010100011111110001001011110111' code: '0111000110010011110110010100011111110001001011110111'
protocol: protocol:
@ -62,5 +61,4 @@ button:
one: [2, 1] one: [2, 1]
inverted: true inverted: true
repeat: repeat:
times: 10 times: 10
- cc1101.end_tx: transceiver

View file

@ -51,8 +51,7 @@ button:
- platform: template - platform: template
name: "Gate" name: "Gate"
on_press: on_press:
- cc1101.begin_tx: transceiver - remote_transmitter.transmit_cc1101:
- remote_transmitter.transmit_rc_switch_raw:
transmitter_id: realtx transmitter_id: realtx
code: '0111000110010011110110010100011111110001001011110111' code: '0111000110010011110110010100011111110001001011110111'
protocol: protocol:
@ -62,5 +61,4 @@ button:
one: [2, 1] one: [2, 1]
inverted: true inverted: true
repeat: repeat:
times: 10 times: 10
- cc1101.end_tx: transceiver

View file

@ -43,8 +43,7 @@ button:
- platform: template - platform: template
name: "Gate" name: "Gate"
on_press: on_press:
- cc1101.begin_tx: transceiver - remote_transmitter.transmit_cc1101:
- remote_transmitter.transmit_rc_switch_raw:
code: '0111000110010011110110010100011111110001001011110111' code: '0111000110010011110110010100011111110001001011110111'
protocol: protocol:
pulse_length: 434 pulse_length: 434
@ -53,5 +52,4 @@ button:
one: [2, 1] one: [2, 1]
inverted: true inverted: true
repeat: repeat:
times: 10 times: 10
- cc1101.end_tx: transceiver

View file

@ -43,8 +43,7 @@ button:
- platform: template - platform: template
name: "Gate" name: "Gate"
on_press: on_press:
- cc1101.begin_tx: transceiver - remote_transmitter.transmit_cc1101:
- remote_transmitter.transmit_rc_switch_raw:
code: '0111000110010011110110010100011111110001001011110111' code: '0111000110010011110110010100011111110001001011110111'
protocol: protocol:
pulse_length: 434 pulse_length: 434
@ -53,5 +52,4 @@ button:
one: [2, 1] one: [2, 1]
inverted: true inverted: true
repeat: repeat:
times: 10 times: 10
- cc1101.end_tx: transceiver

View file

@ -43,8 +43,7 @@ button:
- platform: template - platform: template
name: "Gate" name: "Gate"
on_press: on_press:
- cc1101.begin_tx: transceiver - remote_transmitter.transmit_cc1101:
- remote_transmitter.transmit_rc_switch_raw:
code: '0111000110010011110110010100011111110001001011110111' code: '0111000110010011110110010100011111110001001011110111'
protocol: protocol:
pulse_length: 434 pulse_length: 434
@ -53,5 +52,4 @@ button:
one: [2, 1] one: [2, 1]
inverted: true inverted: true
repeat: repeat:
times: 10 times: 10
- cc1101.end_tx: transceiver

View file

@ -43,8 +43,7 @@ button:
- platform: template - platform: template
name: "Gate" name: "Gate"
on_press: on_press:
- cc1101.begin_tx: transceiver - remote_transmitter.transmit_cc1101:
- remote_transmitter.transmit_rc_switch_raw:
code: '0111000110010011110110010100011111110001001011110111' code: '0111000110010011110110010100011111110001001011110111'
protocol: protocol:
pulse_length: 434 pulse_length: 434
@ -53,5 +52,4 @@ button:
one: [2, 1] one: [2, 1]
inverted: true inverted: true
repeat: repeat:
times: 10 times: 10
- cc1101.end_tx: transceiver

View file

@ -50,8 +50,7 @@ button:
- platform: template - platform: template
name: "Gate" name: "Gate"
on_press: on_press:
- cc1101.begin_tx: transceiver - remote_transmitter.transmit_cc1101:
- remote_transmitter.transmit_rc_switch_raw:
code: '0111000110010011110110010100011111110001001011110111' code: '0111000110010011110110010100011111110001001011110111'
protocol: protocol:
pulse_length: 434 pulse_length: 434
@ -61,4 +60,3 @@ button:
inverted: true inverted: true
repeat: repeat:
times: 10 times: 10
- cc1101.end_tx: transceiver