Hi So first a thank you to all who contributed, I now have a working solution -
This is using a Shelly Pro Plug with Bluetooth Prox turned on and running the Shelly script, ‘universal-blu-to-mqtt.js’ from the Shellly libuary.
This takes any bluetooth message and relay it via mqtt to the broker configured.
Messages look like this for the Shelly Blu RC4-
7c:c6:b6:74:cf:d5 : msg : Object
object
topic: “7c:c6:b6:74:cf:d5”
payload: object
addr: “7c:c6:b6:74:cf:d5”
rssi: -53
local_name: “”
service_data: object
encryption: false
BTHome_version: 2
pid: 83
battery: 100
button: array[4]
0: 254
1: 0
2: 0
3: 0
qos: 0
retain: false
_topic: “7c:c6:b6:74:cf:d5”
_msgid: “06776fa45ab6feb6”
I then created a 2 sensors in configuration.yaml, one for the battery and the other for any message.
# --------------------------------------- Shelly Blue RC Button 4 ---------------------
- name: "ShellyRC4_Bed3_Battery"
unique_id: "shellyRC4-7c:c6:b6:74:cf:d5_BAT"
state_topic: "7c:c6:b6:74:cf:d5"
value_template: '{{ value_json.service_data.battery }}'
json_attributes_topic: "7c:c6:b6:74:cf:d5"
json_attributes_template: '{{ value_json | tojson }}'
unit_of_measurement: "%"
device_class: battery
- name: "Shelly BRC4 Bed 3 analog"
unique_id: "shellyRC4-7c:c6:b6:74:cf:d5-A"
state_topic: "7c:c6:b6:74:cf:d5"
json_attributes_topic: "7c:c6:b6:74:cf:d5"
Once this was done the hard part was isolating each button and press in an automation. I now have one automation containing 20 triggers with ID’s to cover each button, the 4 different press types ( single,double,tripple,long press and release).
I created the automation from from the GUI but have included the code below for refferance, essentially I created a trigger from each value for each button press, the Long press uses the ‘254’ value for more than one second , button held down, then last trigger looks for the release of the button which is a state value of 4, that way Ican use the long press for Dimming, or any thing which needs to increase/decrease.
Buttons are numbered 0,1,2,3 for buttons 1-4.
single press is 1
double press is 2
tripple press is 3
Long press is 4
In each case when the button is pressed down the value for that button is 254, hence why I look for the 254 value for more than 1 second to indicate a long press then end the action with the release value of 4.
alias: automate rc4b1
description: ''
triggers:
- triggers:
- trigger: template
value_template: '{{state_attr(''sensor.shelly_brc4_bed_3_analog'', ''service_data'')[''button''].0
== 1}}'
id: Single_Press
- trigger: template
value_template: '{{state_attr(''sensor.shelly_brc4_bed_3_analog'', ''service_data'')[''button''].0
== 2}}'
id: Double_Press
- trigger: template
value_template: '{{state_attr(''sensor.shelly_brc4_bed_3_analog'', ''service_data'')[''button''].0
== 3}}'
id: Tripple_Press
- trigger: template
value_template: '{{state_attr(''sensor.shelly_brc4_bed_3_analog'', ''service_data'')[''button''].0
== 254}} '
id: Long_Press
for:
hours: 0
minutes: 0
seconds: 1
- trigger: template
value_template: '{{state_attr(''sensor.shelly_brc4_bed_3_analog'', ''service_data'')[''button''].0
== 4}} '
id: Long_Press_Release
conditions: []
actions:
- choose:
- conditions:
- condition: trigger
id:
- Single_Press
sequence:
- action: light.toggle
target:
entity_id: light.bed_4_beam_led
data: {}
- choose:
- conditions:
- condition: trigger
id:
- Long_Press
sequence:
- action: light.turn_on
metadata: {}
data:
brightness_step_pct: 30
target:
entity_id: light.bed_4_beam_led
- repeat:
sequence: []
until:
- condition: trigger
id:
- Long_Press_Release
Any way case closed, hope this helps some one else, and yes their are easier ways to do this, but this fits my purpose maybe it will yours too, enjoy …