Hi, I keep getting this error when trying to run a script to create a home doorbell that pushes a image to telegram.
This is my configuration.yaml file.
# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
# Text to speech
tts:
- platform: google_translate
# Example configuration.yaml entry
camera:
- platform: mqtt
topic: dev/camera
#telegram stuff
telegram_bot:
- platform: polling
api_key: API_KEYHERE
allowed_chat_ids:
- 1123456789
- -11111111
notify:
- name: Telegram
platform: telegram
chat_id: -111111111
#automation
automation:
- alias: Doorbell_pressed_automation
trigger:
platform: mqtt
topic: dev/test
payload: 'Capture!'
action:
- service: automation.turn_off
entity_id: automation.doorbell_pressed_automation
- service: script.turn_on
entity_id: script.doorbell_pressed_script
- delay: "00:00:5"
- service: automation.turn_on
entity_id: automation.doorbell_pressed_automation
#onscript
dev_publish_on_script:
sequence:
- service: mqtt.publish
data: {"topic":"dev/test", "payload":"ON"}
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
homeassistant:
customize: !include customize.yaml
But i’m getting this error:
The following integrations and platforms could not be set up:
dev_publish_on_script
Please check your config and logs.
Logger: homeassistant.setup
Source: setup.py:138
First occurred: 11:39:04 (1 occurrences)
Last logged: 11:39:04
Setup failed for dev_publish_on_script: Integration not found.
tom_l
September 2, 2021, 10:55am
2
You need to put the script under the script key:
script:
dev_publish_on_script:
sequence:
...etc
If you have this:
script: !include scripts.yaml
Then put the script in that file instead.
Also rather than turning the automation off, delay, turn it on again to prevent multiple notifications, delete all that and just put this at the end of your actions:
- delay: "00:00:05"
The default mode for automations is to only run one instance, so if it triggers again while waiting in that delay it will not run. It will generate a warning in the log though (“automation Doorbell_pressed_automation already running”). To suppress that you can do this:
automation:
- alias: Doorbell_pressed_automation
trigger:
platform: mqtt
topic: dev/test
payload: 'Capture!'
action:
- service: automation.turn_off
entity_id: automation.doorbell_pressed_automation
- delay: "00:00:5"
max_exceeded: silent
Thank you. Done that. I cant figure out how to do this now.
“create a template sensor which is displays the time when ‘Capture!’ is published on the dev/test channel by post_image()
. I have a sensor monitoring dev/test with the code”
The code is
sensor:
- platform: mqtt
name: "dev_test"
state_topic: "dev/test"
Not sure how to create a sensor from this. I am following this tutorial but most problems i can figure out but i’m new to home assistant. Homeassistant doorbell
tom_l
September 2, 2021, 11:08am
4
I’d use a triggered template sensor instead:
template:
- trigger:
- platform: mqtt
topic: dev/test
payload: 'Capture!'
sensor:
- name: "Doorbell Pressed at"
state: "{{ now() }}"
This sensor state will have the following format: 2021-09-02 21:09:12.231825+10:00
You can format it however you like though.
See this topic:
After seeing many threads on the forum asking for help with time conversions and calculations using time and realizing I generally had no real understanding of how time worked in HA I decided to dig in and try to figure it out.
After over a week of internet and forum searches I think I’ve now got a lot of it figured out. I’m sure there is more that I don’t have here because sometimes “you don’t know what you don’t know”.
So, since I didn’t know this stuff and because of the number of other pos…
So do i place that in configurations.yaml file? this is where i’m lost as when i’ve gone to the templates bit in homeassistant it’s confusing me.
tom_l
September 2, 2021, 11:16am
6
Yes indeed. In configuration.yaml.
Did that but it’s saying
The following integrations and platforms could not be set up:
Please check your config and logs .
the log shows:
Logger: homeassistant.setup
Source: setup.py:138
First occurred: 12:17:08 (1 occurrences)
Last logged: 12:17:08
Setup failed for template: No setup function defined.
tom_l
September 2, 2021, 11:27am
8
What version of Home Assistant are you running?
System Health
version: 2021.1.5
installation_type: Home Assistant Core
dev: false
hassio: false
docker: false
virtualenv: true
python_version: 3.7.3
os_name: Linux
os_version: 5.10.60+
arch: armv6l
timezone: Europe/London
logged_in: false
can_reach_cert_server: ok
can_reach_cloud_auth: ok
can_reach_cloud: ok
dashboards: 1
mode: auto-gen
resources: 0
tom_l
September 2, 2021, 11:46am
10
monsterstepdad:
version: 2021.1.5
You are 8 releases behind.
That version does not include the new template format. Triggered template sensors were introduced in 2021.4
tried to update to the lastest 2021.9.0 however when ever i use pip3 install --upgrade homeassistant is just reinstalls 2021.1.5 so not sure what i’m doing wrong.
tom_l
September 2, 2021, 2:09pm
12
Not reading and fixing the breaking changes relevant to your config for all the updates in between probably.
Update one version at a time (the last dot release for each major version), read the breaking changes in the relevant release notes blog post and fix them before moving on to the next version.
Ah got it. I needed to upgrade python to 3.8 before anything else. Doing this now and compiling. once that is done I’ll do the version by version update.
Thank you…
@tom_l
Thank you i’ve finished updating homeassistant.
How can i get it to start running a script in /var/www/html/images when it reboots.
It is a py script and contains this:
# combine the MQTT and RF receive codes
import paho.mqtt.client as mqtt
import paho.mqtt.publish as publish
import picamera
import argparse
import signal
import sys
import time
import datetime
import logging
from rpi_rf import RFDevice
rfdevice = None
### camera
camera = picamera.PiCamera()
camera.vflip=False
#
def post_image():
print('Taking photo')
camera.capture('image.jpg')
file_name = 'image_' + str(datetime.datetime.now()) + '.jpg'
camera.capture(file_name) # time-stamped image
with open('image.jpg', "rb") as imageFile:
myFile = imageFile.read()
data = bytearray(myFile)
client.publish('dev/camera', data, mqttQos, mqttRetained) #
client.publish('dev/test', 'Capture!')
print(file_name + 'image published')
#
### MQTT
broker = '10.0.0.1'
topic ='dev/test'
mqttQos = 0
mqttRetained = False
#
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe(topic)
# The callback for when a PUBLISH message is received from the server.
#
def on_message(client, userdata, msg):
payload = str(msg.payload.decode('ascii')) # decode the binary string
print(msg.topic + " " + payload)
process_trigger(payload)
#
def process_trigger(payload):
if payload == 'ON':
print('ON triggered')
post_image()
#
client = mqtt.Client()
client.on_connect = on_connect # call these on connect and on message
client.on_message = on_message
client.username_pw_set(username='user',password='pass') # need this
client.connect(broker)
#client.loop_forever() # don't get past this
client.loop_start() # run in background and free up main thread
### RF
#
def exithandler(signal, frame):
rfdevice.cleanup()
sys.exit(0)
logging.basicConfig(level=logging.INFO, datefmt='%Y-%m-%d %H:%M:%S',
format='%(asctime)-15s - [%(levelname)s] %(module)s: %(message)s', )
parser = argparse.ArgumentParser(description='Receives a decimal code via a 433/315MHz GPIO device')
parser.add_argument('-g', dest='gpio', type=int, default=27,
help="GPIO pin (Default: 27)")
args = parser.parse_args()
signal.signal(signal.SIGINT, exithandler)
rfdevice = RFDevice(args.gpio)
rfdevice.enable_rx()
timestamp = None
logging.info("Listening for codes on GPIO " + str(args.gpio))
code_of_interest = '8388608'
#
while True:
if rfdevice.rx_code_timestamp != timestamp:
timestamp = rfdevice.rx_code_timestamp
print(str(rfdevice.rx_code))
if str(rfdevice.rx_code) == code_of_interest:
post_image()
time.sleep(1) # prevent registering multiple times
time.sleep(0.01)
rfdevice.cleanup()