mirror of
https://github.com/esphome/esphome.git
synced 2024-11-28 01:34:18 +01:00
remote_transmitter.transmit_cc1101
This commit is contained in:
parent
fa5d6955a7
commit
752cd75f46
10 changed files with 50 additions and 55 deletions
|
@ -4,9 +4,12 @@ from esphome import automation, pins
|
|||
from esphome.components import sensor
|
||||
from esphome.components import spi
|
||||
from esphome.automation import maybe_simple_id
|
||||
from esphome.components import remote_base
|
||||
from esphome.const import (
|
||||
CONF_ID,
|
||||
CONF_FREQUENCY,
|
||||
CONF_PROTOCOL,
|
||||
CONF_CODE,
|
||||
UNIT_EMPTY,
|
||||
UNIT_DECIBEL_MILLIWATT,
|
||||
DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
|
@ -14,7 +17,7 @@ from esphome.const import (
|
|||
)
|
||||
|
||||
DEPENDENCIES = ["spi"]
|
||||
AUTO_LOAD = ["sensor"]
|
||||
AUTO_LOAD = ["sensor", "remote_base"]
|
||||
|
||||
CODEOWNERS = ["@gabest11"]
|
||||
|
||||
|
@ -23,12 +26,11 @@ CONF_BANDWIDTH = "bandwidth"
|
|||
# CONF_FREQUENCY = "frequency"
|
||||
CONF_RSSI = "rssi"
|
||||
CONF_LQI = "lqi"
|
||||
CONF_CC1101_ID = "cc1101_id"
|
||||
|
||||
cc1101_ns = cg.esphome_ns.namespace("cc1101")
|
||||
CC1101 = cc1101_ns.class_("CC1101", cg.PollingComponent, spi.SPIDevice)
|
||||
ns = cg.esphome_ns.namespace("cc1101")
|
||||
|
||||
BeginTxAction = cc1101_ns.class_("BeginTxAction", automation.Action)
|
||||
EndTxAction = cc1101_ns.class_("EndTxAction", automation.Action)
|
||||
CC1101 = ns.class_("CC1101", cg.PollingComponent, spi.SPIDevice)
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
cv.Schema(
|
||||
|
@ -54,21 +56,6 @@ CONFIG_SCHEMA = (
|
|||
.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):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
|
@ -85,3 +72,25 @@ async def to_code(config):
|
|||
if CONF_LQI in config:
|
||||
lqi = await sensor.new_sensor(config[CONF_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])
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
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.
|
||||
|
||||
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:
|
||||
|
||||
https://github.com/dbuezas/esphome-cc1101 (the original esphome component)
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/components/spi/spi.h"
|
||||
#include "esphome/components/remote_base/rc_switch_protocol.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace cc1101 {
|
||||
|
@ -89,14 +90,15 @@ class CC1101 : public PollingComponent,
|
|||
void end_tx();
|
||||
};
|
||||
|
||||
template<typename... Ts> class BeginTxAction : public Action<Ts...>, public Parented<CC1101> {
|
||||
public:
|
||||
void play(Ts... x) override { this->parent_->begin_tx(); }
|
||||
};
|
||||
template<typename... Ts> class CC1101RawAction : public remote_base::RCSwitchRawAction<Ts...>, public Parented<CC1101> {
|
||||
protected:
|
||||
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:
|
||||
void play(Ts... x) override { this->parent_->end_tx(); }
|
||||
};
|
||||
|
||||
} // namespace cc1101
|
||||
|
|
|
@ -51,8 +51,7 @@ button:
|
|||
- platform: template
|
||||
name: "Gate"
|
||||
on_press:
|
||||
- cc1101.begin_tx: transceiver
|
||||
- remote_transmitter.transmit_rc_switch_raw:
|
||||
- remote_transmitter.transmit_cc1101:
|
||||
transmitter_id: realtx
|
||||
code: '0111000110010011110110010100011111110001001011110111'
|
||||
protocol:
|
||||
|
@ -62,5 +61,4 @@ button:
|
|||
one: [2, 1]
|
||||
inverted: true
|
||||
repeat:
|
||||
times: 10
|
||||
- cc1101.end_tx: transceiver
|
||||
times: 10
|
|
@ -51,8 +51,7 @@ button:
|
|||
- platform: template
|
||||
name: "Gate"
|
||||
on_press:
|
||||
- cc1101.begin_tx: transceiver
|
||||
- remote_transmitter.transmit_rc_switch_raw:
|
||||
- remote_transmitter.transmit_cc1101:
|
||||
transmitter_id: realtx
|
||||
code: '0111000110010011110110010100011111110001001011110111'
|
||||
protocol:
|
||||
|
@ -62,5 +61,4 @@ button:
|
|||
one: [2, 1]
|
||||
inverted: true
|
||||
repeat:
|
||||
times: 10
|
||||
- cc1101.end_tx: transceiver
|
||||
times: 10
|
|
@ -43,8 +43,7 @@ button:
|
|||
- platform: template
|
||||
name: "Gate"
|
||||
on_press:
|
||||
- cc1101.begin_tx: transceiver
|
||||
- remote_transmitter.transmit_rc_switch_raw:
|
||||
- remote_transmitter.transmit_cc1101:
|
||||
code: '0111000110010011110110010100011111110001001011110111'
|
||||
protocol:
|
||||
pulse_length: 434
|
||||
|
@ -53,5 +52,4 @@ button:
|
|||
one: [2, 1]
|
||||
inverted: true
|
||||
repeat:
|
||||
times: 10
|
||||
- cc1101.end_tx: transceiver
|
||||
times: 10
|
|
@ -43,8 +43,7 @@ button:
|
|||
- platform: template
|
||||
name: "Gate"
|
||||
on_press:
|
||||
- cc1101.begin_tx: transceiver
|
||||
- remote_transmitter.transmit_rc_switch_raw:
|
||||
- remote_transmitter.transmit_cc1101:
|
||||
code: '0111000110010011110110010100011111110001001011110111'
|
||||
protocol:
|
||||
pulse_length: 434
|
||||
|
@ -53,5 +52,4 @@ button:
|
|||
one: [2, 1]
|
||||
inverted: true
|
||||
repeat:
|
||||
times: 10
|
||||
- cc1101.end_tx: transceiver
|
||||
times: 10
|
|
@ -43,8 +43,7 @@ button:
|
|||
- platform: template
|
||||
name: "Gate"
|
||||
on_press:
|
||||
- cc1101.begin_tx: transceiver
|
||||
- remote_transmitter.transmit_rc_switch_raw:
|
||||
- remote_transmitter.transmit_cc1101:
|
||||
code: '0111000110010011110110010100011111110001001011110111'
|
||||
protocol:
|
||||
pulse_length: 434
|
||||
|
@ -53,5 +52,4 @@ button:
|
|||
one: [2, 1]
|
||||
inverted: true
|
||||
repeat:
|
||||
times: 10
|
||||
- cc1101.end_tx: transceiver
|
||||
times: 10
|
|
@ -43,8 +43,7 @@ button:
|
|||
- platform: template
|
||||
name: "Gate"
|
||||
on_press:
|
||||
- cc1101.begin_tx: transceiver
|
||||
- remote_transmitter.transmit_rc_switch_raw:
|
||||
- remote_transmitter.transmit_cc1101:
|
||||
code: '0111000110010011110110010100011111110001001011110111'
|
||||
protocol:
|
||||
pulse_length: 434
|
||||
|
@ -53,5 +52,4 @@ button:
|
|||
one: [2, 1]
|
||||
inverted: true
|
||||
repeat:
|
||||
times: 10
|
||||
- cc1101.end_tx: transceiver
|
||||
times: 10
|
|
@ -50,8 +50,7 @@ button:
|
|||
- platform: template
|
||||
name: "Gate"
|
||||
on_press:
|
||||
- cc1101.begin_tx: transceiver
|
||||
- remote_transmitter.transmit_rc_switch_raw:
|
||||
- remote_transmitter.transmit_cc1101:
|
||||
code: '0111000110010011110110010100011111110001001011110111'
|
||||
protocol:
|
||||
pulse_length: 434
|
||||
|
@ -61,4 +60,3 @@ button:
|
|||
inverted: true
|
||||
repeat:
|
||||
times: 10
|
||||
- cc1101.end_tx: transceiver
|
||||
|
|
Loading…
Reference in a new issue