@gonzotek : Thanks for your assistance.
This is the full string that I get from the gateway:
{XC_SUC}[{"type":"IN","sid":"01","adr":"01","config":"","state":"012400","deviceType":"01"},{"type":"IN","sid":"02","adr":"02","config":"","state":"241C00","deviceType":"01"},{"type":"IN","sid":"03","adr":"03","config":"","state":"002400","deviceType":"01"},{"type":"IN","sid":"04","adr":"04","config":"","state":"241400","deviceType":"01"},{"type":"IN","sid":"05","adr":"05","config":"","state":"243000","deviceType":"01"}]
I am interested in the state
attribute of all elements of type == "IN"
, addressed through the adr
attribute, so a hash map of pairs adr
=> state
(filtered for type == "IN"
would include all data I need.
state
is always a 6-digit all-uppercase hexadecimal string with the first byte representing some bit-encoded status flags, the second byte representing the tilt position of the blinds (0x00 is fully closed, 0x3c is fully open), and the third byte represents the position in percent (0x00 … 0x64).
So far my plan was to receive the data once from the gateway and use JSONPath to filter and select the state string presented as a sensor for every single window, here an example of the blind with adr == "04"
:
rest:
- resource: http://192.168.88.101/command?XC_FNC=GetStates
method: GET
scan_interval: 5
sensor:
- name: "Arbeitszimmer Beschattung"
json_attributes_path: '$.[?(@.adr == "04" && @.type == "IN")]'
value_template: "OK"
json_attributes:
- "state"
And then to decode the data for position and tilt position inside the cover entity, likewise for the blind with adr == "04"
as an example:
cover:
- platform: template
covers:
arbeitszimmer_beschattung:
friendly_name: "Arbeitszimmer Beschattung"
unique_id: arbeitszimmer_beschattung
device_class: blind
position_template: "{{ state_attr('sensor.arbeitszimmer_beschattung', 'state')[4:6] | int(base=16) % 101 }}"
tilt_template: "{{ (state_attr('sensor.arbeitszimmer_beschattung', 'state')[2:4] | int(base=16) * 5 / 3) | int % 101 }}"
icon_template: >-
{% if state_attr('sensor.arbeitszimmer_beschattung', 'state')[4:6] != '00' %}
mdi:blinds-horizontal
{% else %}
mdi:blinds-horizontal-closed
{% endif %}
open_cover:
service: rest_command.internorm_blinds_open
data:
gateway: 192.168.88.101
adr: '04'
close_cover:
service: rest_command.internorm_blinds_close
data:
gateway: 192.168.88.101
adr: '04'
stop_cover:
service: rest_command.internorm_blinds_stop
data:
gateway: 192.168.88.101
adr: '04'
set_cover_position:
service: rest_command.internorm_blinds_set_position
data:
gateway: 192.168.88.101
adr: '04'
position: "{{position}}"
set_cover_tilt_position:
service: rest_command.internorm_blinds_set_tilt
data:
gateway: 192.168.88.101
adr: '04'
tilt: "{{tilt}}"
With your example in mind, my new plan was to store all JSON data in a single sensor.mediola_device_states
entity and let the cover templates filter and select the state attribute to decode position and tilt position directly from this entity:
sensor:
- platform: rest
name: Mediola Device States
resource: http://192.168.88.101/command?XC_FNC=GetStates
method: GET
scan_interval: 5
This ressource returns in the 424 bytes long string at the beginning of this reply.