diff --git a/docker/Dockerfile b/docker/Dockerfile index 6cfe07f..45131d1 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -11,10 +11,11 @@ WORKDIR /app # Install enoceanmqtt and requirements RUN apk add --no-cache git && \ python3 -m pip install --upgrade pip && \ - pip3 install pyyaml && \ - pip3 install tinydb && \ + pip3 install pyyaml==6.0.1 && \ + pip3 install tinydb==4.7.1 && \ + pip3 install paho-mqtt==1.6.1 && \ pip3 install git+https://github.com/mak-gitdev/enocean.git && \ - git clone https://github.com/embyt/enocean-mqtt.git && \ + git clone -b master --single-branch --depth 1 https://github.com/embyt/enocean-mqtt.git && \ cd enocean-mqtt && python3 setup.py develop && cd .. && \ if [ "${BUILD_VERSION}" = "head" ]; then \ echo "Installing from repository head" && \ diff --git a/enoceanmqtt/overlays/homeassistant/mapping.yaml b/enoceanmqtt/overlays/homeassistant/mapping.yaml index fac0e36..e09432d 100644 --- a/enoceanmqtt/overlays/homeassistant/mapping.yaml +++ b/enoceanmqtt/overlays/homeassistant/mapping.yaml @@ -38,6 +38,172 @@ payload_off: "off" value_template: >- {% if value_json.LC == 1 %}on{% else %}off{% endif %} + 0x08: + device_config: + command: "CMD" + channel: "CMD" + log_learn: "" + direction: "" + answer: "" + entities: + - component: "switch" + name: "switch" + config: + state_topic: "CMD4" + state_on: "100" + state_off: "0" + value_template: "{{ value_json.OV }}" + command_topic: "req" + payload_on: > + {"CMD":"1","DV":"0","IO":"0","OV":"100","send":"clear"} + payload_off: > + {"CMD":"1","DV":"0","IO":"0","OV":"0","send":"clear"} + device_class: outlet + - component: "sensor" + name: "energy" + config: + state_topic: "CMD7" + state_class: "total_increasing" + device_class: "energy" + unit_of_measurement: "Wh" + value_template: >- + {% if value_json.UN == 0 %} + {{ (value_json.MV|int / 3600)|int }} + {% elif value_json.UN == 1 %} + {{ value_json.MV }} + {% elif value_json.UN == 2 %} + {{ value_json.MV|int * 1000 }} + {% else %} + {{ states(entity_id)|int(default=0) }} + {% endif %} + - component: "sensor" + name: "power" + config: + state_topic: "CMD7" + state_class: "measurement" + device_class: "power" + unit_of_measurement: "W" + value_template: >- + {% if value_json.UN == 3 %} + {{ value_json.MV }} + {% elif value_json.UN == 4 %} + {{ value_json.MV|int * 1000 }} + {% else %} + {{ states(entity_id)|int(default=0) }} + {% endif %} + - component: "button" + name: "query_energy" + config: + command_topic: "req" + payload_press: >- + {"CMD":"6","qu":"0","IO":"30","send":"clear"} + - component: "button" + name: "query_power" + config: + command_topic: "req" + payload_press: >- + {"CMD":"6","qu":"1","IO":"30","send":"clear"} + - component: "button" + name: "query_status" + config: + command_topic: "req" + payload_press: >- + {"CMD":"3","IO":"30","send":"clear"} + - component: "switch" + name: "reset_meas" + config: + command_topic: "__trash" + icon: "mdi:numeric-0-circle-outline" + - component: "select" + name: "meas_type" + config: + options: + - "Query only - Energy in Ws" + - "Query only - Energy in Wh" + - "Query only - Energy in KWh" + - "Query only - Power in W" + - "Query only - Power in KW" + - "Query & Auto - Energy in Ws" + - "Query & Auto - Energy in Wh" + - "Query & Auto - Energy in KWh" + - "Query & Auto - Power in W" + - "Query & Auto - Power in KW" + command_topic: "__trash" + icon: "mdi:tune" + - component: "number" + name: "meas_MAT" + config: + command_topic: "__trash" + min: "10" + max: "2550" + step: "10" + mode: "box" + unit_of_measurement: "s" + icon: "mdi:timer-refresh-outline" + - component: "number" + name: "meas_MIT" + config: + command_topic: "__trash" + min: "1" + max: "255" + step: "1" + mode: "box" + unit_of_measurement: "s" + icon: "mdi:timer-refresh-outline" + - component: "number" + name: "meas_MD" + config: + command_topic: "__trash" + min: "0" + max: "4095" + step: "1" + mode: "box" + icon: "mdi:equalizer" + - component: "button" + name: "set_meas" + config: + command_topic: "req" + command_template: >- + {% set ns = namespace() %} + {% for entity in device_entities(device_id(entity_id)) %} + {% if entity is search('meas_type',ignorecase=True) %} + {% if states(entity) is search ('only') %}{% set ns.RM = 0 %}{% else %}{% set ns.RM = 1 %}{% endif %} + {% if states(entity) is search ('Energy') %}{% set ns.ep = 0 %}{% else %}{% set ns.ep = 1 %}{% endif %} + {% if states(entity) is search ('KWh') %}{% set ns.UN = 2 %} + {% elif states(entity) is search (' KW') %}{% set ns.UN = 4 %} + {% elif states(entity) is search (' Wh') %}{% set ns.UN = 1 %} + {% elif states(entity) is search (' Ws') %}{% set ns.UN = 0 %} + {% else %}{% set ns.UN = 3 %} + {% endif %} + {% elif entity is search('reset_meas',ignorecase=True) %} + {% if is_state(entity, "on") %}{% set ns.RE = 1 %}{% else %}{% set ns.RE = 0 %}{% endif %} + {% elif entity is search('meas_mat',ignorecase=True) %} + {% set ns.MAT = (states(entity)|int /10)|int(default=10) %} + {% elif entity is search('meas_mit',ignorecase=True) %} + {% set ns.MIT = states(entity)|int(default=1) %} + {% elif entity is search('meas_md',ignorecase=True) %} + {% set ns.MD_MSB = (states(entity)|int/16)|int(default=0) %} + {% set ns.MD_LSB = (states(entity)|int%16)|int(default=0) %} + {% endif %} + {% endfor %} + {"CMD":"5","RM":"{{ns.RM}}","RE":"{{ns.RE}}","ep":"{{ns.ep}}","IO":"0","MD_LSB":"{{ns.MD_LSB}}","UN":"{{ns.UN}}","MD_MSB":"{{ns.MD_MSB}}","MAT":"{{ns.MAT}}","MIT":"{{ns.MIT}}", "send":"clear"} + icon: "mdi:download" + - component: binary_sensor + name: "OC" + config: + state_topic: "CMD4" + payload_on: "on" + payload_off: "off" + value_template: >- + {% if value_json.OC == 1 %}on{% else %}off{% endif %} + - component: binary_sensor + name: "LC" + config: + state_topic: "CMD4" + payload_on: "on" + payload_off: "off" + value_template: >- + {% if value_json.LC == 1 %}on{% else %}off{% endif %} 0x09: device_config: command: "CMD" @@ -3964,118 +4130,7 @@ {"COM":"2","EDIM":"0","RMP":"1","EDIMR":"0","STR":"0","SW":"0","send":"clear"} 0xF6: 0x02: - 0x01: - device_config: - command: "" - channel: "" - log_learn: "" - direction: "" - answer: "" - entities: - - component: binary_sensor - name: "pressed" - config: - state_topic: "" - value_template: "{{ value_json.EB }}" - payload_on: "1" - payload_off: "0" - - component: binary_sensor - name: "AI_pressed" - config: - state_topic: "" - payload_on: "on" - payload_off: "off" - value_template: >- - {% if (value_json.EB and value_json.R1 == 0) or (value_json.SA and value_json.R2 == 0) %}on{% else %}off{% endif %} - - component: binary_sensor - name: "AO_pressed" - config: - state_topic: "" - payload_on: "on" - payload_off: "off" - value_template: >- - {% if (value_json.EB and value_json.R1 == 1) or (value_json.SA and value_json.R2 == 1) %}on{% else %}off{% endif %} - - component: binary_sensor - name: "BI_pressed" - config: - state_topic: "" - payload_on: "on" - payload_off: "off" - value_template: >- - {% if (value_json.EB and value_json.R1 == 2) or (value_json.SA and value_json.R2 == 2) %}on{% else %}off{% endif %} - - component: binary_sensor - name: "BO_pressed" - config: - state_topic: "" - payload_on: "on" - payload_off: "off" - value_template: >- - {% if (value_json.EB and value_json.R1 == 3) or (value_json.SA and value_json.R2 == 3) %}on{% else %}off{% endif %} - virtual: - - component: select - name: "action" - config: - options: - - "None" - - "AO" - - "AI" - - "BO" - - "BI" - - "AO + BO" - - "AO + BI" - - "AI + BO" - - "AI + BI" - - "BO + AO" - - "BO + AI" - - "BI + AO" - - "BI + AI" - command_topic: "req" - command_template: >- - {% set R1, EB, R2, SA, T21, NU = 0, 0, 0, 0, 1, 0 %} - {% set id = {"AI":"0","AO":"1","BI":"2","BO":"3"} %} - {% set action = value.split(" + ") %} - {% if value is not search('None') %}{% set EB, NU, R1 = 1, 1, id[action[0]] %}{% endif %} - {% if action|length==2 %}{% set SA, R2 = 1, id[action[1]] %}{% endif %} - {"R1":{{R1}},"EB":{{EB}},"R2":{{R2}},"SA":{{SA}},"T21":{{T21}},"NU":{{NU}},"send":"clear"} - - component: "switch" - name: "AI" - config: - command_topic: "__trash" - - component: "switch" - name: "AO" - config: - command_topic: "__trash" - - component: "switch" - name: "BI" - config: - command_topic: "__trash" - - component: "switch" - name: "BO" - config: - command_topic: "__trash" - - component: "button" - name: "send" - config: - command_topic: "req" - command_template: >- - {% set ns = namespace(action=[]) %} - {% for entity in device_entities(device_id(entity_id)) %} - {% if entity is search('AI',ignorecase=True) and is_state(entity, "on") %} - {% set ns.action = ns.action+["0"] %} - {% elif entity is search('AO',ignorecase=True) and is_state(entity, "on") %} - {% set ns.action = ns.action+["1"] %} - {% elif entity is search('BI',ignorecase=True) and is_state(entity, "on") %} - {% set ns.action = ns.action+["2"] %} - {% elif entity is search('BO',ignorecase=True) and is_state(entity, "on") %} - {% set ns.action = ns.action+["3"] %} - {% endif %} - {% endfor %} - {% set R1, EB, R2, SA, T21, NU = 0, 0, 0, 0, 1, 0 %} - {% if ns.action|length>0 %}{% set EB, NU, R1 = 1, 1, ns.action[0] %}{% endif %} - {% if ns.action|length>1 %}{% set SA, R2 = 1, ns.action[1] %}{% endif %} - {"R1":{{R1}},"EB":{{EB}},"R2":{{R2}},"SA":{{SA}},"T21":{{T21}},"NU":{{NU}},"send":"clear"} - icon: "mdi:download" - 0x02: + 0x01: &F60201 device_config: command: "" channel: "" @@ -4186,6 +4241,7 @@ {% if ns.action|length>1 %}{% set SA, R2 = 1, ns.action[1] %}{% endif %} {"R1":{{R1}},"EB":{{EB}},"R2":{{R2}},"SA":{{SA}},"T21":{{T21}},"NU":{{NU}},"send":"clear"} icon: "mdi:download" + 0x02: *F60201 0x04: 0x01: device_config: diff --git a/standalone/install.sh b/standalone/install.sh index a3a8108..85c0eed 100644 --- a/standalone/install.sh +++ b/standalone/install.sh @@ -87,8 +87,8 @@ printf "\n==================================================\n" printf "Entering install directory: ${INSTALL_DIR}\n\n" cd ${INSTALL_DIR} -package_install pyyaml -package_install tinydb +package_install pyyaml==6.0.1 +package_install tinydb==4.7.1 printf "\n==================================================\n" printf "Install Custom Python EnOcean Library\n\n" @@ -97,6 +97,8 @@ pip3 install --user --force-reinstall git+https://github.com/mak-gitdev/enocean. printf "\n==================================================\n" printf "Install enocean-mqtt\n\n" rm -rf enocean-mqtt +# Quick Fix issue for issue mak-gitdev/HA_enoceanmqtt#122 (Force use of 1.6.1 as >=2.0.0 break enoceanmqtt) +package_install paho-mqtt==1.6.1 git clone -b master --single-branch --depth 1 https://github.com/embyt/enocean-mqtt.git cd enocean-mqtt && pip3 install --user -e . && cd ..