Using clock, timer and PIR to send IR transmitter command
Moderators: grovkillen, Stuntteam, TD-er
Using clock, timer and PIR to send IR transmitter command
Hello all, I'm new to ESPEasy and have a question about timer and clock
I want to transmit an IR code through an IR transmitter if the following criteria is met:
1. Current time must be between 10am and 2pm
2. No input from my PIR has been detected for the last 60 mins
What's the best practice to achieve this with espeasy please?
Any help would be greatly appreciated.
Cassio
I want to transmit an IR code through an IR transmitter if the following criteria is met:
1. Current time must be between 10am and 2pm
2. No input from my PIR has been detected for the last 60 mins
What's the best practice to achieve this with espeasy please?
Any help would be greatly appreciated.
Cassio
Re: Using clock, timer and PIR to send IR transmitter command
I woudl start with keeping track of "not detected in last N minutes".
Let's assume you get an event when receiving a PIR signal.
Not sure how the event is formatted, but let's call it "PIR#value".
When receiving this event, you set a timer to 60 minutes. See: https://espeasy.readthedocs.io/en/lates ... imer#timer
When this timer expires, you check for the time range and send out a command to send your IR signal.
But this will run into an issue when you don't receive any PIR signal during the day as the timer will not be set.
So we have to start a timer ourselves which will set this all in motion at 10am.
You still need to decide whether you need to send an IR signal at 10am or start the timer at 10am.
Let's assume you get an event when receiving a PIR signal.
Not sure how the event is formatted, but let's call it "PIR#value".
When receiving this event, you set a timer to 60 minutes. See: https://espeasy.readthedocs.io/en/lates ... imer#timer
When this timer expires, you check for the time range and send out a command to send your IR signal.
Code: Select all
on PIR#value do
timerSet,1,3600 // reset timer to 60 minutes
endon
on Rules#timer=1 do
if %systime% > 10:00:00 and %systime% < 14:00:00
// Send your IR command
// Set your timer again
timerSet,1,3600 // Set timer to 60 minutes
endif
endon
So we have to start a timer ourselves which will set this all in motion at 10am.
You still need to decide whether you need to send an IR signal at 10am or start the timer at 10am.
Code: Select all
on Clock#time=All,10:00 do
timerSet,1,3600 // Set timer to 60 minutes
endon
Re: Using clock, timer and PIR to send IR transmitter command
Wow thanks, this forum is wow... thanks for the code...
I made it work on esphome, but espeasy is more indicated for my peculiar need.
I made it work on esphome, but espeasy is more indicated for my peculiar need.
Code: Select all
esphome:
name: menano-ar
platform: ESP8266
board: esp01_1m
# Aqui defino em qual rede o ESP8266 vai conectar
wifi:
ssid: "MySSID"
password: "MyTopSecretPassword"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "My Fallback Hotspot"
password: "AnotherTopSecretPass"
# Acertando o relógio pegando dos sntp padrões dele (0.pool.ntp.org, 1.pool.ntp.org e 2.pool.ntp.org)
time:
- platform: sntp
id: sntp_time
timezone: America/Sao_Paulo
# Aqui defino o GPIO0 do ESP-01 como emissor IR
remote_transmitter:
pin: GPIO0
carrier_duty_percent: 50%
# Aqui defino o GPIO2 do ESP-01 como receptor IR
remote_receiver:
pin:
number: GPIO2
inverted: True
dump: all
# Essa função abaixo cria um switch dentro do home assistant, que posso transformar num botão no front end para executar
switch:
- platform: template
name: Lg Power Button
turn_on_action:
- remote_transmitter.transmit_lg:
data: 0x20DF10EF
nbits: 32
# Aqui estou definindo que o GIPO1 é sensor de movimento e avisando ele para rodar o script abaixo quando tiver movimento
binary_sensor:
- platform: gpio
pin: GPIO1
name: "PIR Menano"
device_class: motion
id: pir_menano
on_press:
then:
- script.execute: keep_ac_on
interval:
- interval: 1min
then:
- script.execute: turn_off_ac
script:
# Script executado de 1 em 1 minuto para tentar validar horário e atividade do sensor de movimento e desligar o ar caso não há movimento e estiver de dia.
- id: turn_off_ac
mode: single
then:
- if:
condition:
and:
- lambda: |-
return id(sntp_time).now().hour > 8;
- lambda: |-
return id(sntp_time).now().hour < 22;
- lambda: |-
if (id(pir_menano).state) {
return false;
} else {
return true;
}
then:
- logger.log: "Turn Off AC"
- remote_transmitter.transmit_lg:
data: 0x20DF10EF
nbits: 32
else:
- logger.log: "Keep AC on"
# Script executado sempre que houver movimento no PIR
- id: keep_ac_on
mode: restart
then:
- lambda: |-
id(pir_menano).publish_state(true);
- delay: 60min
- lambda: |-
id(pir_menano).publish_state(false);
captive_portal:
# Enable logging
logger:
level: DEBUG
# Enable Home Assistant API
api:
ota:
Re: Using clock, timer and PIR to send IR transmitter command
You might want to remove any passwords from your message.
/Ton (PayPal.me)
Re: Using clock, timer and PIR to send IR transmitter command
I just removed the SSID/pass from your post
Re: Using clock, timer and PIR to send IR transmitter command
TD-er wrote: ↑18 Apr 2021, 10:22 I woudl start with keeping track of "not detected in last N minutes".
Let's assume you get an event when receiving a PIR signal.
Not sure how the event is formatted, but let's call it "PIR#value".
When receiving this event, you set a timer to 60 minutes. See: https://espeasy.readthedocs.io/en/lates ... imer#timer
When this timer expires, you check for the time range and send out a command to send your IR signal.
But this will run into an issue when you don't receive any PIR signal during the day as the timer will not be set.Code: Select all
on PIR#value do timerSet,1,3600 // reset timer to 60 minutes endon on Rules#timer=1 do if %systime% > 10:00:00 and %systime% < 14:00:00 // Send your IR command // Set your timer again timerSet,1,3600 // Set timer to 60 minutes endif endon
So we have to start a timer ourselves which will set this all in motion at 10am.
You still need to decide whether you need to send an IR signal at 10am or start the timer at 10am.Code: Select all
on Clock#time=All,10:00 do timerSet,1,3600 // Set timer to 60 minutes endon
What about I do the following? Wouldn't it solve the issue?
Code: Select all
on System#Boot do
timerSet,1,3600. // set the timer on boot
on PIR#value do
timerSet,1,3600 // reset timer to 60 minutes
endon
on Rules#timer=1 do
if %systime% > 10:00:00 and %systime% < 14:00:00
// Send your IR command
// Set your timer again
timerSet,1,3600 // Set timer to 60 minutes
else
timerSet,1,3600 // Set timer to 60 minutes
endif
endon
Re: Using clock, timer and PIR to send IR transmitter command
It might also work, but you have to think about its behavior when the ESP boots at the following times:
- 8:59
- 9:01
- 9:59
- 10:01
All with and without PIR events occurring.
If those all work out fine, then that would be a good solution too.
This is slightly simpler as you set the timer both in the if and the else branch.
- 8:59
- 9:01
- 9:59
- 10:01
All with and without PIR events occurring.
If those all work out fine, then that would be a good solution too.
Code: Select all
on Rules#timer=1 do
if %systime% > 10:00:00 and %systime% < 14:00:00
// Send your IR command
endif
// Set your timer again
timerSet,1,3600 // Set timer to 60 minutes
endon
Re: Using clock, timer and PIR to send IR transmitter command
So does this looks good?
Code: Select all
on System#Boot do
timerSet,1,3600. // set the timer on boot
on PIR#Switch=1 do
timerSet,1,3600 // reset timer to 60 minutes
endon
on Rules#timer=1 do
if %systime% > 08:00:00 and %systime% < 22:00:00
// Send your IR command
IRSEND,'{"protocol":"NIKAI","data":"0xD5F2A","bits":24}'
// Set your timer again
timerSet,1,3600 // Set timer to 60 minutes
endif
timerSet,1,3600 // Set timer to 60 minutes
endon
Re: Using clock, timer and PIR to send IR transmitter command
Why not like this:
Removed a duplicate timerSet and you missed an "endon" at the System#boot block.
Code: Select all
on System#Boot do
timerSet,1,3600. // set the timer on boot
endon
on PIR#Switch=1 do
timerSet,1,3600 // reset timer to 60 minutes
endon
on Rules#timer=1 do
if %systime% > 08:00:00 and %systime% < 22:00:00
// Send your IR command
IRSEND,'{"protocol":"NIKAI","data":"0xD5F2A","bits":24}'
endif
timerSet,1,3600 // Set timer to 60 minutes
endon
Who is online
Users browsing this forum: Ahrefs [Bot] and 54 guests