Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 96121

Bitmanipulation for status and command via mqtt payload

$
0
0

@demeulemeesterdries wrote:

Hi all

I’m pretty new to Home assistant.
The whole reason I tried to set it up is because I have rather dumb “domotics” light control system.
It can only toggle output based on input switches (each with an own address strap).

What I have done to augment the domotics system is develop an arduino shield myself containing some i2c contolled IO expanders so I can trick the system to simulate button switches.
Also I’m able to report back the current status of each output of my light system.
Now I’m able to control the system via a stupid app and udp commands.

Now, i would like to connect HA as a control.

I set up mqtt and my arduino is perfectly capable of sending his status as a 32 bit mask (just an integer number in the mqtt data body). Each bit representing the state of one of the outputs.

Now the hard part (for me):
Below you see the mqtt related configuration in my configuration.yaml. What I would like to do is to be able to let HA communicatate via one mqtt Topic and 32bit value to control all lights.

So in my example, the kitchen is situated as bit 0 in the bitmask

I tried 2 versions to get the state:
1:

    light:
      - platform: mqtt
        name: "kitchen"
        command_topic: "DOMESTIA/SWITCHES"
        state_topic: "DOMESTIA/SWITCHES/STATUS"
        state_value_template: "{{ value|int|bitwise_and(1) > 0 }}"
        payload_on: "on"
        payload_off: "off"

2:

    light:
      - platform: mqtt
        name: "kitchen"
        command_topic: "DOMESTIA/SWITCHES"
        state_topic: "DOMESTIA/SWITCHES/STATUS"
        state_value_template: < 
            {% if {{ value|int|bitwise_and(1) }} > 0 %}
            "On"
            {% else %}
            "Off"
            {% endif %}
        payload_on: "On"
        payload_off: "Off"

Both no success. I checked around for templating but I cannot connect the code snippets i found to get the result I would like to achieve.

2nd part of my question is how i would be able to create the command being build up with the same kind of 32 bit mask as a command (So Command topic to set/clear the domotic outputs based on the 32 bit integer

I know it would be easier with building jsons strings to communicate between both systems, but i lack program memory to store all the parse code…

I hope somebody can get me started in the correct direction.

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 96121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>