Hi Folks
I have munged some great work by others to automate a set of Somfy blinds I have, using MQTT, a D1 Mini, 433.42 Mhz transmitter and some bad yaml. I can control the blinds successfully via covers configured like this - with similar config for all 4 blinds:
- platform: mqtt
name: "Somfy Blind 1"
device_class: "blind"
command_topic: "homeassistant/livingRoom/blind1"
availability_topic: "homeassistant/virtual-somfy-remote/status"
payload_open: "u"
payload_close: "d"
payload_stop: "s"
retain: false
What I want to do is to “save” the value of a rolling code that gets incremented each time my “virtual” remote transmits. I pass this information back via an MQTT “ack”, which contains the following JSON formatted data:
{"Name":"blind2","RemoteID": "0x121312","Code": 107,"Cmd": "u"}
My first attempt is using a number of sensors. My first sensor subscribes to the common MQTT “ack” and populates attributes in the sensor state:
- platform: mqtt
name: Somfy Blind Ack
state_topic: "homeassistant/virtual-somfy-remote/ack"
json_attributes_topic: "homeassistant/virtual-somfy-remote/ack"
I can see this working, with the sensor.somfy_blind_ack getting set correctly:
Name: blind2
RemoteID: 0x121312
Code: 107
Cmd: u
friendly_name: Somfy Blind Ack
I then have template sensors for each of the different blinds, so I can extract and store the rolling code for each blind:
- platform: template
sensors:
somfy_blind1_rc:
friendly_name: "Somfy Blind1 Last Rolling Code"
value_template: >-
{% if is_state_attr('sensor.somfy_blind_ack', 'Name','blind1') %}
{{state_attr('sensor.somfy_blind_ack', 'Code') }}
{% endif %}
somfy_blind2_rc:
friendly_name: "Somfy Blind2 Last Rolling Code"
value_template: >-
{% if is_state_attr('sensor.somfy_blind_ack', 'Name','blind2') %}
{{state_attr('sensor.somfy_blind_ack', 'Code') }}
{% endif %}
And these work to a certain extent as well - but what happens (and it makes sense) is that when the “Blind2” ack comes back, all the other sensors get reset, as their value_template obviously gets wiped.
Basically - I either need a way of keeping the existing sensor values in all but the one getting updated, or another way of attacking this. I don’t really need these to be separate sensors - I just want to save a log of the rolling codes (ultimately so when my D1 mini ultimately craps itself - I can restore the codes).
This is my first attempt at templates (apart from copying the good work of those before me) - but no amount of searching has led me to a similar setup.
Any pointers appreciated.
Cheers,
Chris