Hello everyone,
I know very little things about coding.
I’m running Hassio 0.94.2 on a raspberry pi3 B+.
I bought an Ultrasonic Sensor (JSN-SR04T-2.0) and connected to pi via GPIO as shown in the photo, with trigger on 23 and echo on 24.
I created (copied actually from a python coding page) a python script and put it in /config/python_scripts
The script is:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
TRIG = 23
ECHO = 24
print ("Distance Measurement In Progress")
GPIO.setup(TRIG,GPIO.OUT)
GPIO.setup(ECHO,GPIO.IN)
GPIO.output(TRIG, False)
print ("Waiting For Sensor To Settle")
time.sleep(2)
GPIO.output(TRIG, True)
time.sleep(0.00001)
GPIO.output(TRIG, False)
while GPIO.input(ECHO)==0:
pulse_start = time.time()
while GPIO.input(ECHO)==1:
pulse_end = time.time()
pulse_duration = pulse_end - pulse_start
distance = pulse_duration * 17150
distance = round(distance, 2)
print ("Distance:",distance,"cm")
GPIO.cleanup()
In order to display its values on Hassio I inserted in configuration.yaml the following.
sensor:
- platform: command_line
name: Tank
command: “python3 /config/python_scripts/distancemeter.py”
On log I get:
2019-06-14 15:23:56 WARNING (MainThread) [homeassistant.helpers.entity] Update of sensor.tank is taking over 10 seconds
2019-06-14 15:24:01 ERROR (SyncWorker_8) [homeassistant.components.command_line.sensor] Timeout for command: python3 /config/python_scripts/distancemeter.py
What am I doing wrong?
Any help would be appreciated…