Palakis / esphome-native-hdmi-cec

HDMI-CEC implementation for ESPHome
Other
40 stars 11 forks source link

Templating #2

Closed Minims closed 4 months ago

Minims commented 7 months ago

Hello,

First of all thanks for this work !

I'm trying to get a Service in HomeAssistant. So i define this in esphome:

api:
  services:
    - service: hdmi_cec_send
      variables:
        cec_destination: int
        cec_data: int[]
      then:
        - hdmi_cec.send:
            destination: !lambda 'return cec_destination;'
            data: !lambda 'return cec_data;'

but i have this error :

<unicode string>:54:14: error: could not convert 'cec_data' from 'vector<int>' to 'vector<unsigned char>'

Any Idea how i can fix this ?

Minims commented 6 months ago

fixed with that:

  services:
    - service: hdmi_cec_send
      variables:
        cec_destination: int
        cec_data: int[]
      then:
        - hdmi_cec.send:
            destination: !lambda 'return static_cast<unsigned char>(cec_destination);'
            data: !lambda 'std::vector<unsigned char> charVector; for (int i : cec_data) { charVector.push_back(static_cast<unsigned char>(i)); } return charVector;'

And it works with esp-idf framework, thx !!

Minims commented 6 months ago

On more thing, is there a way to template source i have tried, but i'm unable to compile.

Palakis commented 4 months ago

@Minims Just added this right now. Thanks for the feedback!