Code Monkey home page Code Monkey logo

Comments (7)

Arksine avatar Arksine commented on July 24, 2024 1

Based on the info you provided, it looks like the state_topic needs to be zigbee2mqtt/Friendly_name. The state topic is the topic Moonraker subscribes to and listens for updates. The "zigbee2mqtt" client should publish all updates to this topic. If the zigbee sets the retain flag on this topic then the query_topic is optional.

Again, based on the info provided, the query_topic appears it should be zigbee2mqtt/Friendly_name/get/state, with no payload.

from moonraker.

Arksine avatar Arksine commented on July 24, 2024 1

Unfortunately I can't help with setting up Mainsail, as its a separate project. Moonraker just exposes the APIs which frontend applications like Mainsail can choose to implement. I don't know if Mainsail can show data from generic sensors or how to configure it if it can.

from moonraker.

Arksine avatar Arksine commented on July 24, 2024

Without moonraker.log it isn't clear what is happening with the command topic, but I suspect the primary issue is that the device can't initialize and thus commands won't be sent. If you need to send a payload with the query topic you need to configure the query_payload option (see the docs. You can use Jinja2 to encode a dict to json if that is what is required for your zigbee client. Moonraker has some brief Jinja2 docs, and the full Jinja template documentation is available here.

from moonraker.

Travis90x avatar Travis90x commented on July 24, 2024

Thank for your reply! Uploaded below moonraker.log and klippy.log with no usefull log

Ok, if I set
command_topic: zigbee2mqtt/Friendly_name/set/state
command_payload: {command}
query_topic: zigbee2mqtt/Friendly_name/set/state
query_payload: toggle

The Zigbee2mqtt device toggle in loop ON-OFF every 5 seconds because of query_topic that works as SET and not GET the state

But the Power button doesn't work, so I suppose that is necessary to configure correctly the query_topic that it's needed to enable command_topic

I tested with MQTTX (client mqtt)

zigbee2mqtt/Friendly_name/get
zigbee2mqtt/Friendly_name/get state

give me
Zigbee2MQTT:error 2024-03-26 22:51:08: Invalid message 'null', skipping...

If use
zigbee2mqtt/Friendly_name/get/state
I obtain

Zigbee2MQTT:info 2024-03-26 22:52:12: MQTT publish: topic 'zigbee2mqtt/Friendly_name', payload '{"current":0,"energy":0,"indicator_mode":"off/on","linkquality":232,"over_current_breaker":"ON","over_current_threshold":65,"over_voltage_breaker":"ON","over_voltage_threshold":265,"power":0,"power_breaker":"ON","power_outage_memory":"restore","power_threshold":13,"state":"ON","temperature":26.94,"temperature_breaker":"ON","temperature_threshold":100,"under_voltage_breaker":"ON","under_voltage_threshold":75,"update":{"installed_version":-1,"latest_version":-1,"s

So I don't need query_payload, right?

Otherwise I can use it with
zigbee2mqtt/Friendly_name/get {"state": ""}
I obtain the payload with MQTTX
but If I set

query_topic: zigbee2mqtt/Friendly_name/get 
query_payload: {"state": ""}

The Power Button Disappear because the correct Jinja2 output should be
query_payload: {'{"state": ""}'}

Correct it, Power still no work

I try
query_topic: zigbee2mqtt/Friendly_name/get/state
query_payload: state
MQTTX obtain payload, But the Power button still no work

If I set
state_topic: zigbee2mqtt/Friendly_name/set/state
state_response_template: toggle
Power button disappear

state_topic: zigbee2mqtt/Friendly_name/get/state
state_response_template: state
Power Button goes dark

###################################
###################################
For my reminder
Button Name (MQTT) goes dark:
###################################
state_topic: zigbee2mqtt/Friendly_name/get
state_response_template: {'{"state": ""}'}
query_topic: zigbee2mqtt/Friendly_name/get
query_payload: {'{"state": ""}'}
###################################
state_topic: zigbee2mqtt/Friendly_name/get/state
state_response_template: state
{% set resp = payload|fromjson %}
{ resp["state"]|lower }
###################################
state_topic: zigbee2mqtt/Friendly_name/get/state
state_response_template: state
###################################
state_topic: zigbee2mqtt/Friendly_name/get/state
state_response_template:
###################################
state_topic: zigbee2mqtt/Friendly_name/get/state
state_response_template:
query_topic: zigbee2mqtt/Friendly_name/get/state
query_payload:
###################################
state_topic: zigbee2mqtt/Friendly_name/get/state
state_response_template: state
query_topic: zigbee2mqtt/Friendly_name/get/state
query_payload: state
###################################
state_topic: zigbee2mqtt/Friendly_name/get
state_response_template:
{% set resp = payload|fromjson %}
{ resp["state"]|lower }
query_topic: zigbee2mqtt/Friendly_name/get
query_payload: {'{"state": ""}'}
###################################

###################################
###################################
Button Name (MQTT) goes light:
###################################
state_topic: zigbee2mqtt/Friendly_name/get
state_response_template: {payload}
###################################
state_topic: zigbee2mqtt/Friendly_name/set
state_response_template: state
###################################
state_topic: zigbee2mqtt/Friendly_name/get
state_response_template:
{% set resp = payload|fromjson %}
{ resp["state"]|lower }
query_topic: zigbee2mqtt/Friendly_name/get/state
query_payload: state
###################################
state_topic: zigbee2mqtt/Friendly_name/get
state_response_template:
{% set resp = payload|fromjson %}
{ resp["state"]|lower }
query_topic: zigbee2mqtt/Friendly_name/get/state
query_payload: {'{"state": ""}'}

klippy.log
moonraker.log
immagine

from moonraker.

Travis90x avatar Travis90x commented on July 24, 2024

Thank you, now it works, you earned a ko-fi
The issue was the state_topic: that want "zigbee2mqtt/Friendly_name" and not "zigbee2mqtt/Friendly_name/get"

[power MQTT]
type: mqtt
command_topic: zigbee2mqtt/Friendly_name/set/state
command_payload: {command}
state_topic: zigbee2mqtt/Friendly_name
state_response_template:
    {% set resp = payload|fromjson %}
    { resp["state"] }
query_topic: zigbee2mqtt/Friendly_name/get/state
query_after_command: false
locked_while_printing: true

from moonraker.

Travis90x avatar Travis90x commented on July 24, 2024

Now I'm configuring the powermeter function with

[sensor mqtt_powermeter]
type: mqtt
name: Powermeter
state_topic: zigbee2mqtt/Friendly_name
state_response_template:
{% set notification = payload|fromjson %}
{set_result("power", notification["apower"]|float)}
{set_result("voltage", notification["voltage"]|float)}
{set_result("current", notification["current"]|float)}

But the documentation is poor to understand how show in Mainsail those sensor values.

from moonraker.

Arksine avatar Arksine commented on July 24, 2024

As the original issue has been resolved I'm going to close this.

from moonraker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.