I am stuck. I’ve tried to figure this out for a good few hours now, but I just can’t figure out the syntax.
I have 4 byte blocks that come in on the serial port. Byte 2 is the address.
Using IF statements, I want to be able to match the address to the entity.
Heres my code. Everything works other than the RF1 entity which I would like to respond when the address coming in = 1
sensor:
- platform: serial
scan_interval: 0
serial_port: /dev/ttyUSB0
baudrate: 9600
bytesize: 8
parity: N
stopbits: 1
- platform: template
sensors:
RFinfo:
friendly_name: RF info
unit_of_measurement: ""
value_template: "{{ states('sensor.serial_sensor') [1:2] | ord }}"
RF1:
friendly_name: RF1 device
unit_of_measurement: ""
value_template: {{ IF states('sensor.serial_sensor') [1:2] | ord = 1 }}
Triggered
Hope someone can help as this has me baffled.
Thanks.
Is there any way to have sensors and binary_sensor to work on the serial port?
I should have mentioned that I have temperature sensors and PIRs on the serial port.
Both are working, but I’d like to use binary_sensor for the PIRs as I need auto_off.
What you are currently using, the Serial Sensor integration, is the only one purpose-built to receive data from a serial port. A garden-variety Template Sensor (or Template Binary Sensor) cannot do that.
Hi Taras. Thanks for your time.
However, I’m giving up on the Serial port. It has a tendency to just stop working after some time. I see this documented on other threads here as well.
I’ve even taken a look at the code for it, but I’m not well up on Python.
I’m going to switch to using RESTful to update the sensors.
I’ve already experimented with the ‘Advanced REST client’ plugin for Chrome. It works flawlessly.
Just need to get it to work via an ESP8266 now. But so far I can’t get it working, so might be posting another help request soon
Thanks again for your time though. I’m amazed how responsive the community is on here. My previous Home Automation software’s forum used to take weeks for any response !