Hi everyone. I am new to home assistant. Just managed to set up HASSIO on Raspberry Pi 4. I’m trying to use the Pi’s bluetooth to track presence in the living room and turn on some lights. Since the seating area in the living room is close to the pi, the rssi value shows between 0 to -5. So I have setup the following automation:-
Not sure why this is not working. Sometimes the automation shows its triggered, but the switches don’t turn on. Most of the times, it just don’t trigger at all.
I hope someone experienced can help me out.
check your condition. I’m not sure / can’t remember if you can have a condition like this as time cannot be after 19 and before 7 at the same time.
Try and see if you can split into 2 conditions:
condition:
- condition: time
before: '07:00'
- condition: time
after: '19:00'
If that still doesn’t work, remove the conditions and see if it triggers at all
Other thing I’d do is replace
value_template: '{{ states.device_tracker.mi_phone.attributes.rssi | int > -5 }}'
with
value_template: '{{ state_attr("device_tracker.mi_phone","attributes.rssi") | int > -5 }}'
This way it will not error on null or not available
I am really really confused as to how home assistant calculations work. For an example :
example 1 : {{ state_attr("device_tracker.mi_phone", "rssi") }} returns -29 {{ state_attr("device_tracker.mi_phone", "rssi") | int > -10 }} returns true
example 2 : {{ state_attr("device_tracker.mi_phone", "rssi") }} returns -26 {{ state_attr("device_tracker.mi_phone", "rssi") | int > -40 }} returns true
according to this. -29 is greater than -10. but -26 is also greater than -40.
how does this work???
p.s - just incase i wasn’t clear. i edited the code as follows : -
1. rssi value is {{state_attr("device_tracker.mi_phone", "rssi") }}
2. is it greater than -40 ? {{state_attr("device_tracker.mi_phone", "rssi") | int > -40 }}
3. is it greater than -5 ? {{state_attr("device_tracker.mi_phone", "rssi") | int > -5 }}
The result i got from the above is :-
rssi value is (-19,)
is it greater than -40 ? True
is it greater than -5 ? True
p.s. 2 -
went on to test simpler instructions which seems correct.
All I can think of at the moment is that there’s something else that’s not right in the data returned by your sensor.
Just did a test with my Freezer sensor: {{states("sensor.kitchen_freezer_temperature")}} returns -15.3 {{states("sensor.kitchen_freezer_temperature") | int > -10}} returns False {{states("sensor.kitchen_freezer_temperature") | int > -20}} returns True
I wonder if you somehow have a trailing space in your value that screws the conversion to an int?
What result do you get for this? {{ state_attr("device_tracker.mi_phone", "rssi") | length }}
If your rssi value is -29, above should return 3…
Hi. I managed to solve it. The problem was as follows:-
{{ state_attr("device_tracker.mi_phone","attributes.rssi") | int }} returns 0 irrespective of the value {{ state_attr("device_tracker.mi_phone","attributes.rssi") }} returns.
. so 0 is > than any negative numbers. Hence my solution is as follows:-
Yes it would as your attribute is called rssi, not attribute.rssi, therefore you can put whatever you want in that 2nd quotes, if it’s not a valid attribute, it’ll always return 0…
Looks like you’ve edited your value _template as I was replying
This would suggest state_attr("device_tracker.mi_phone", "rssi") doesn’t not return a number but a string composed of a number between brackets, e.g. (-26)
If so then yes your value_template now makes sense and explains why your earlier tests failed as (-26) | int would return 0 all the time
This would suggest state_attr("device_tracker.mi_phone", "rssi") doesn’t not return a number but a string composed of a number between brackets, e.g. (-26).
You’re right. Now i just have to figure out how to add more device trackers to the template.
you probably want to look at a bayesian binary sensor for this.
It takes a bit to understand, but it’s really powerful. This article helped me understand how it works.
Very interesting. So you are using the Bluetooth built in on the raspberry pi to track presence in the living room, correct? It detects your phone, right?
How did you set that up? Can you please point me in the other direction.
I tried adding Bluetooth integration to Hassio, but I get nothing.
Hi. I gave up on it. Im no longer using hassio due to a network issue.
The Bluetooth detection is slow. If you expect your light to on as soon as you enter the room, forget it. You will need to sit in the dark room for about a minute or so before it detects.
And its really difficult to get the correct strength to distance.